我一直在搜索,但無法找到信息來幫助我糾正此問題。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