我一直在搜索,但无法找到信息来帮助我纠正此问题。if if python
在python中练习编程我正在研究家庭自动化的控制代码。我开始使用温度转换计算器,并且运行良好。然后,我把它放在另一个“如果”给它的功能来改变温度和读取当前温度。这使我的转换器“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."
如果这是其他地方回答,我根本无法找到它,请链接。
什么是你输入你试过吗?请确保匹配CASE – baloo 2013-03-24 18:41:46
@baloo,我已将它们逐个匹配,但正如向我解释的那样,我的“转换”语句是将“转换”视为始终为真的测试。 – user2134635 2013-03-24 18:58:36