the_input = input('请输入以‘F’ or ‘C’ 结尾的温度:')
if the_input[-1] in ['F' , 'f']:
C = (eval(the_input[0:-1]) - 32 ) / 1.8
print("输出结果是:{:.2f}C".format(C))
elif the_input[-1] in ['c' ,'C']:
F = (eval(the_input[0:-1])* 1.8 + 32 )
print("输出结果是:{:.2f}F".format(F))
else :
print("输入错误了吧?")
注意:
- eval
- {:.2f}.format
- if elif else
- if something[-1] in [‘a’,‘b’]: