我正在尝试创建一个函数,该函数将根据正在转换的温度将温度转换为我们想要的温度。然而,当我测试代码时,它的输出是无的
def convertTemperature(T, unitFrom, unitTo):
if unitFrom=="Fahrenheit" and unitTo=="Celsius":
T=(T-32)/1.8
return T
elif unitFrom=="Kelvin" and unitTo=="Celcius":
T=T-273.15
return T
elif unitFrom=="Celcius" and unitTo=="Fahrenheit":
T=1.8*T+32
return T
elif unitFrom=="Kelvin" and unitTo=="Fahrenheit":
T=1.8*T-459.67
return T
elif unitFrom=="Celcius" and unitTo=="Kelvin":
T=T+273.15
return T
elif unitFrom=="Fahrenheit" and unitTo=="Kelvin":
T=(T*459.67)/1.8
return T
unitFrom参数是当前温度,T是温度,unitTo是我要转换的温度。
我试着用print(convertTemperature(50.0, "Fahrenheit", "Celcius"))
测试它,但结果是没有
这只是一个拼写错误
Celsius
而不是Celcius
这会奏效的
嗨,你用错词了 那就是塞尔修斯 除了拼写错误,你的程序是正确的
相关问题 更多 >
编程相关推荐