現在問題來自我的if語句,即使我鍵入「是」,它仍然會說「無效輸入」並重新執行我的main()函數。不知道什麼是錯誤的。不確定我是否正確使用了if,elif語句。沒有得到我想要的輸入
condition=input("What is the condition of the phone(New or Used)?")
if(condition != "New") or (condition != "new"):
print("Invalid input")
return main()
elif(condition != "Used") or (condition != "used"):
print("Invalid input")
return main()
gps=input("Does the phone have gps(Yes or No)?")
if(gps != "Yes") or (gps != "yes"):
print("Invalid input")
return main()
elif(gps != "No") or (gps != "no"):
print("Invalid input")
return main()
wifi=input("Does the phone have wifi(Yes or No)?")
if(wifi != "Yes") or (wifi != "yes"):
print("Invalid input")
return main()
elif(wifi != "No") or (wifi != "no"):
print("Invalid input")
return main()
camera=input("Does the phone have a camera(Yes or No)?")
if(camera != "Yes") or (camera != "yes"):
print("Invalid input")
return main()
elif(camera != "No") or (camera != "no"):
print("Invalid input")
return main()
您的代碼顯示了在「if語句」中組合多個條件的主題缺乏理解。最好再多做一些Google搜索。 – StillLearnin
對於python 2用「raw_input」代替「input」 –
假設你輸入「Yes」,想想第一次檢查的結果是什麼。這是錯誤的,因此執行下降到「elif」 – StillLearnin