Python温度转换器输出为无

Python温度转换器输出为无,python,function,temperature,Python,Function,Temperature,我正在尝试创建一个函数,该函数将根据正在转换的温度将温度转换为我们想要的温度。然而,当我测试代码时,它的输出是无的 def convertTemperature(T, unitFrom, unitTo): if unitFrom=="Fahrenheit" and unitTo=="Celsius": T=(T-32)/1.8 return T elif unitFrom=="Kelvin" and unitTo==&q

我正在尝试创建一个函数,该函数将根据正在转换的温度将温度转换为我们想要的温度。然而,当我测试代码时,它的输出是无的

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,“华氏度”,“摄氏度”))测试它,但输出结果是没有的。

这只是拼写错误
摄氏度
不是
摄氏度

这会奏效的

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"))

嗨,你用错词了 那就是塞尔修斯 您的程序是正确的,除了拼写错误

您有“Celsius”和“Celcius”。