Python 温度转换

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("输入错误了吧?")

注意:

  1. eval
  2. {:.2f}.format
  3. if elif else
  4. if something[-1] in [‘a’,‘b’]:

你可能感兴趣的:(python)