用python计算转换温度

原创
2015/09/03 17:09
阅读数 115

用python编写一个简单的温度(华氏-摄氏/摄氏-华氏)转换程序。

代码如下:

 #-*- charset:utf-8 -*-
#This program will follow users intention to convert F to C or the contray
typeNo = eval(input("Do you want to convert Fah to Cel or convert Cel to Fah,enter 1 for F to C,enter 2 for C to F:"))
if typeNo == 1:
    data = eval(input("Please enter your data:"))
    c = (data - 32) * 5 / 9
    print(data,"Fahrenheit to Celsius is:",round(c,1)," C")
elif typeNo == 2:
    data = eval(input("Please enter your data:"))
    f = data * 9 / 5 + 32
    print(data,"Celsius to Fahrenheit is:",round(f,1)," F")
elif (typeNo != 1) and (typeNo != 2):
    print("Input error!")

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
0 收藏
0
分享
返回顶部
顶部