【发布时间】:2017-09-25 10:42:51
【问题描述】:
#Programme to covert Farenheight to Celcius
F=input("Enter Value:")
F=((F-32)/9)*5
print("The temperature is ",F,"Degrees Celcius")
当我尝试运行它时,它显示 TypeError: unsupported operand type(s) for -: 'str' and 'int'
【问题讨论】:
-
input返回一个str您需要将其转换为浮点数才能使其工作 -
F = int(input('..')) -
有道理,谢谢。我现在把它写成这样 F=int(input("Enter Value:") Celcius=((F-32)/9)*5 print("The temperature is ",Celcius,"Degrees Celsius") 现在在 celsius 'invalid syntax' 下的计算行上说?
-
您错过了 cmets 中代码的 int() 的右括号
-
好的,现在可以了。谢谢大家