Python 温度转换器输出为 none
Python Temperature converter output is none
我正在尝试创建一个函数,该函数将根据要转换的温度将温度转换为我们想要的温度。然而,当我测试它时,我的代码的输出是 none。
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"))
测试它,但输出是 none.
只是拼写错误Celsius
不是Celcius
这会起作用
def convertTemperature(T, unitFrom, unitTo):
if unitFrom=="Fahrenheit" and unitTo=="Celsius":
T=(T-32)/1.8
return T
elif unitFrom=="Kelvin" and unitTo=="Celsius":
T=T-273.15
return T
elif unitFrom=="Celsius" 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=="Celsius" and unitTo=="Kelvin":
T=T+273.15
return T
elif unitFrom=="Fahrenheit" and unitTo=="Kelvin":
T=(T*459.67)/1.8
return T
print(convertTemperature(50.0, "Fahrenheit", "Celsius"))
嗨,你用错了摄氏度这个词
会是 Celcius
除了拼写错误,你的程序是正确的
我正在尝试创建一个函数,该函数将根据要转换的温度将温度转换为我们想要的温度。然而,当我测试它时,我的代码的输出是 none。
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"))
测试它,但输出是 none.
只是拼写错误Celsius
不是Celcius
这会起作用
def convertTemperature(T, unitFrom, unitTo):
if unitFrom=="Fahrenheit" and unitTo=="Celsius":
T=(T-32)/1.8
return T
elif unitFrom=="Kelvin" and unitTo=="Celsius":
T=T-273.15
return T
elif unitFrom=="Celsius" 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=="Celsius" and unitTo=="Kelvin":
T=T+273.15
return T
elif unitFrom=="Fahrenheit" and unitTo=="Kelvin":
T=(T*459.67)/1.8
return T
print(convertTemperature(50.0, "Fahrenheit", "Celsius"))
嗨,你用错了摄氏度这个词 会是 Celcius 除了拼写错误,你的程序是正确的