温度转换-python

#接收一段字符串
TempStr = input("请输入带有符号的温度值:")

#如果 TS 最后一位是大写或是小写 f 
if TempStr[-1] in ['F','f']:
#  TS 0 到 -1 位不包含 -1 的切片
    C = (eval(TempStr[0:-1]) - 32)/1.8
#输出
    print("转换后的温度是{:.2f}C".format(C))
#否则如果 TS 最后一位是大写或小写 c
elif TempStr[-1] in ['C','c']:
#切片
    F = 1.8*eval(TempStr[0:-1]) + 32
#输出
    print("转换后的温度是{:.2f}F".format(F))
else:
    print("输入格式错误")

猜你喜欢

转载自www.cnblogs.com/xuefangzhou/p/9877021.html
今日推荐