美文网首页
Code_TempConvert

Code_TempConvert

作者: 帕博雷克斯丢丢 | 来源:发表于2018-01-31 13:44 被阅读0次

编写一个摄氏度和华氏度相互转换的小程序。

下面是代码部分:

# -*- coding utf-8 -*-

#TempConvert

#华氏度和摄氏度相互转换

print("输入温度值,华氏以F结尾,摄氏度以C结尾。")

in_temp = input("请输入温度:")

if in_temp[-1] in ['c', 'C']:
    print("您输入的为摄氏度%.1fC,转换为华氏度是%.1fF。" % (float(in_temp[0:-1]), float(in_temp[0:-1]) * 1.8 + 32))
elif in_temp[-1] in ["f", "F"]:
    print("您输入的为华氏度%.1fF,转换为摄氏度是%.1fC。" % (float(in_temp[0:-1]), float(in_temp[0:-1]) / 1.8 - 32))
else:
    print("输入错误")

相关文章

  • Code_TempConvert

    编写一个摄氏度和华氏度相互转换的小程序。 下面是代码部分:

网友评论

      本文标题:Code_TempConvert

      本文链接:https://www.haomeiwen.com/subject/ooikzxtx.html