在第 3 行,名为 temp_unit
的变量不被视为变量,并且显示无效语法。
temp = int(input("what is the Temperature?:")
temp_unit = input("Celcius or Farenheit?:")
if temp_unit == "C" or temp_unit=="c":
print("The given temperature in Fahrenheit is "+(9/5)*(temp+32))
else:
print("The given temperature in Celcius is "+(5/9)*(temp-32))
最佳答案
您需要添加括号,因此应该是这样的:
temp=int(input("what is the Temperature?:"))
temp_unit= input("Celcius or Farenheit?:")
if temp_unit == "C" or temp_unit=="c":
print("The given temperature in Fahrenheit is "+(9/5)*(temp+32))
else:
print("The given temperature in Celcius is "+(5/9)*(temp-32))
关于python - 在为用户输入分配变量时如何修复代码中的 "invalid syntax"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55345004/