可实现在线摄氏度(CELSIUS EQUALS)、华氏度(FAHENHEIT EQUALS)、开氏度(KELVIN EQUALS)、兰氏度(RANKINE EQUALS)、列氏度(REAUMUR EQUALS)五种温度计量单位间的互转互换。
摄氏度(C) 华氏度(F) 开氏度(K) 兰氏度(Ra) 列氏度(Re)
- 摄氏到华氏的换算 f = c * 9 /5 +32
- 摄氏到开尔文的换算 k = c + 273.15
- 摄氏到兰金的换算 R = c * 9/5 +491.67
- 华氏到摄氏的换算 c = (c - 32) * (5/9)
- 华氏到开尔文的换算 k = (f + 459.67) * (5/9)
- 华氏到兰金的换算 r = f + 459.67
def c_to_f(c): #摄氏到华氏的换算
return c * (9/5) + 32
def c_to_k(c): #摄氏到开尔文的换算
return c + 273.15
def c_to_r(c): # 摄氏到兰金的换算
return c * (9/5) +491.67
def f_to_c(f): #华氏到摄氏的换算
return (f - 32) * ( 5 / 9 )
def k_to_c(k): #开尔文到摄氏的换算
return k - 273.15
def r_to_c(r): # 兰金到摄氏的换算
return (r - 491.67) * (5/9)
def order_if(order,temperature): #指令逻辑判断
if int(order) and int(order)>4 or int(order) <0:
return ()
elif eval(order) == 1:
return temperature,c_to_f(temperature),c_to_k(temperature),c_to_r(temperature)
elif eval(order) == 2:
c = f_to_c(temperature)
return c,temperature,c_to_k(c),c_to_r(c)
elif eval(order) ==3:
c = k_to_c(temperature)
return c,c_to_f(c),temperature,c_to_r(c)
elif eval(order) == 4:
c= r_to_c(temperature)
return c,c_to_f(c),c_to_k(c),temperature
def print_format(list):
#输出格式化
if not list:
print("您选择的温度性质错误,值范围[1-4]")
else:
print('''
摄氏度:{}
华氏度:{}
开氏度:{}
兰金: {}'''.format(list[0],list[1],list[2],list[3]))
def main():
#主函数
print("""
-------温度转换器---------
1.摄氏度
2.华氏度
3.开氏度
4.兰金
**************************
""")
order = input("请输入指令")
temperature = eval(input("请输入温度"))
print_format(order_if(order,temperature))
main()