This topic requires to calculate the value of the following piecewise function (x Is an arbitrary real number entered from the keyboard ):
If you enter a non number , The output “Input Error!”
Enter a real number in one line x.
Press in a line ”y=result” Format output , among result Keep two decimal places .
-2
y=3.00
x=input() if not(x.isalpha()): x=eval(x) if x<=-2: print("y={:.2f}".format(-2*x-1)) elif -2<x<=1: print("y={:.2f}".format(3)) elif x>1: print("y={:.2f}".format(2*x+1)) else: print("Input Error!")
Calculation a Divide b, The result is rounded to the nearest , Retain 2 Decimal place .
The input consists of two lines , One real number per line
The normal calculation result is a real number , When user input b by 0 Time output " Divide by zero error "
5 0
Divide by zero error
a=eval(input()) b=eval(input()) if b==0: print(" Divide by zero error ") else: print("{:.2f}".format(a/b))
problem :KiKi This year, 5 Year old , Have been able to recognize 100 Non negative integers within , And be able to do 100 The addition of nonnegative integers within . however ,BoBo The teacher found that KiKi Greater than or equal to 100 When calculating positive integers of , The following rules : 1. Only the last two digits of the number are retained , for example : Yes KiKi Come on 1234 Equivalent to 34; 2. If the result is greater than or equal to 100, that KIKI Only the last two digits of the calculated results are retained , If ten of the two are 0, Only one bit is reserved . for example :45+80 = 25 A nonnegative integer is required a and b, simulation KiKi The operation rules of the algorithm calculate a+b Value .
Two 100 Non negative integers within
kiki The result of the calculation is
45 80
25
a=eval(input()) b=eval(input()) if a+b>=100: print("{}".format(a+b-100)) else: print("{}".format(a+b))
The community in order to subsidize poor families , For all incomes below 2000 element ( Not included 2000 element ) The family of , The increase is equivalent to its income 30% Subsidies for . Write a program to realize : Enter a list of incomes for several families ( On the same line , Separated by commas ), Calculate and output the list of household income after the increase of subsidies . Each revenue output is followed by a space , There is no space after the last income .
1500,1800,2100,2500,1200
1950.0 2340.0 2100.0 2500.0 1560.0
2000,2023,1980,1000
2000.0 2023.0 2574.0 1300.0
a=list(eval(input())) for i in range(0,len(a)): if a[i]<2000: a[i]=a[i]+a[i]*0.3 for i in a: print("{:.1f}".format(i),end=" ")
Body mass index ( English is Body Mass Index, abbreviation BMI), Its value is weight divided by the square of height . The unit of weight is kilogram , height The unit is rice. .BMI At present, it is a standard commonly used in the world to measure the degree of weight and health . Here is 16 People over the age of BMI chart surface
BMI
explain
BMI<18
Super light
18<=BMI<25
standard
25<=BMI<27
overweight
27<=BMI
obesity
Write a program , Enter the user's weight (Kg) And height ( rice ), Show it BMI value , And make an explanatory evaluation .
weight , height
Super light / standard / overweight / One of the obesity .
70,1.75
standard
a,b=map(eval,input().split(",")) c=a/(b**2) if c<18: print(" Super light ") elif 18<=c<25: print(" standard ") elif 25<=c<27: print(" overweight ") else: print(" obesity ")
There are two different systems of temperature characterization : Centigrade (Celsius) And Fahrenheit (Fabrenheit).
Please write a program to convert user input Fahrenheit to Celsius , Or convert the input Celsius to Fahrenheit .
The conversion algorithm is as follows :(C In degrees Celsius 、F Is Fahrenheit )
C = ( F - 32 ) / 1.8
F = C * 1.8 + 32
Requirements are as follows :
(1) The input and output centigrade are in capital letters C start , The temperature can be an integer or a decimal , Such as :C12.34 It means centigrade 12.34 degree ;
(2) The input and output Fahrenheit are in capital letters F start , The temperature can be an integer or a decimal , Such as :F87.65 It means centigrade 87.65 degree ;
(3) Do not consider the problem of abnormal input , Output two decimal places ;
(4) Use input() When obtaining test case input , Do not add the prompt string .
C12.34
F54.21
C12.34
F54.21
a=input() if a[0]=="C": temp=eval(a[1:]) print("F{:.2f}".format(temp*1.8+32)) else: temp=eval(a[1:]) print("C{:.2f}".format((temp-32)/1.8))