我一直在搜索,但找不到帮助我纠正此问题的信息。
为了练习 Python 编程,我正在编写用于家庭自动化的控制代码。我从温度转换计算器开始,效果很好。然后我把它放在另一个“if”中,让它具有改变温度和读取当前温度的功能。这将我的转换器“if”作为我的控制“if”的子项。该程序打开良好,但只进入转换器的行。它不适用于作为一般控制一部分的“elif”语句。以下:
while True:
task = (raw_input("What would you like to do? "))
if task == 'Convert' or 'convert':
ask = raw_input("C to get Celsius, F to get Fahrenheit: ")
if ask == 'F':
Cconvert = float(raw_input("Temp in C: "))
F = Cconvert * 9 / 5 + 32
print F, 'F'
elif ask == 'C':
Fconvert = float(raw_input("Temp in F: "))
C = ((Fconvert - 32) * 5) / 9
print C, 'C'
else:
print "That is not a temperature measurement I understand."
elif task == "ChangeTemp":
temptype = raw_input("Celsius or Fahrenheit? ")
if temptype == "Celcius" or "celsius":
temp = float(raw_input("New Temp: ")), str(temptype)
elif temptype == "Fahrenheit" or "fahrenheit":
temp = float(raw_input("New Temp: ")), str(temptype)
else:
print "That is not a temperature measurement I understand."
elif task == "SetTemp":
print temp
else:
print "I do not know what you are asking."
如果在其他地方回答了这个问题而我根本找不到它,请链接。