if input("Raining? ") == "yes":
print("Then you should take an umbrella")
if input("Raining? ") == "no":
print("Then you should not take an umbrella ")
所以我希望這兩個同時檢查是或否,所以當我輸入 no 時,列印的答案應該是“那么你不應該帶傘”但問題是當我說沒有示例時它會問兩次:
Raining? no
Raining? no
Then you should not take an umbrella
有什么想法可以讓我完成這項作業嗎?
我只想問你下雨了嗎?不,答案是那么你不應該帶傘,不要問你兩次,第二次有效
uj5u.com熱心網友回復:
在宣告之前詢問輸入if。
例如:
value = input("Raining? ")
if value == "yes":
print("Then you should take an umbrella")
elif value == "no":
print("Then you should not take an umbrella")
uj5u.com熱心網友回復:
只需保存輸入以供以后比較。
inp = input("Raining? ")
if inp == "yes":
print("Then you should take an umbrella")
elif inp == "no":
print("Then you should not take an umbrella ")
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/405554.html
標籤:
下一篇:Lubridate:陳述句自行回傳TRUE/FALSE,但在函式中會引發“需要TRUE/FALSE的缺失值”錯誤
