Example -python temperature conversion achieved:
Temperature portray two different systems: degrees Celsius (Celsius) and ° F (Fahrenheit).
Please write programs to convert Fahrenheit to Celsius user input, or input conversion Celsius to Fahrenheit.
Conversion algorithm is as follows: (C indicates Celsius, F represents F)
C = ( F - 32 ) / 1.8
F = C * 1.8 + 32
Requirements are as follows:
(1) the case can be input and output ends degrees letters C, the temperature may be an integer or decimal, such as: 12.34C refers to degrees Celsius 12.34;
F (2) the case can be input and output ends with the letter F., The temperature may be an integer or decimal, such as: 87.65F refers to 87.65 degrees Fahrenheit;
When (3) the output of two decimal places, the input format error, system outputs: an input format error;
(4) using the input () to get the test case input, not to increase the prompt string
TempStr = input() if TempStr[-1] in ['F','f']: C = (eval(TempStr[0:-1])-32)/1.8 print("{:.2f}C".format(C)) elif TempStr[-1] in ['C','c']: F = eval(TempStr[0:-1])*1.8+32 print("{:.2f}F".format(F)) else: print("输入格式错误")
to sum up: