我需要幫助在“else”部分添加一個回圈,以便它在不理解時重新提出問題。這是代碼。
answer = raw_input("What did you think of this program?")
is answer = 'yes':
print("Thank you! Have a nice day.")
elif answer = 'no':
print("Thank you for your feedback, I will try to improve this program")
else:
print("Sorry I don't understand, please try again.")
uj5u.com熱心網友回復:
將整個事情放在一個while回圈中,如果他們回答是或否,則退出回圈。
while True:
answer = raw_input("What did you think of this program?")
if answer == 'yes':
print("Thank you! Have a nice day.")
break
elif answer == 'no':
print("Thank you for your feedback, I will try to improve this program")
break
else:
print("Sorry I don't understand, please try again.")
uj5u.com熱心網友回復:
您可以嘗試用函式包裝邏輯并遞回呼叫它。
您有一些語法錯誤(單個等號和 'is' 而不是 'if' 等),但您可以在下面找到更正的代碼
def get_answer():
answer = input("What did you think of this program?")
if answer == 'yes':
print("Thank you! Have a nice day.")
elif answer == 'no':
print("Thank you for your feedback, I will try to improve this program")
else:
print("Sorry I don't understand, please try again.")
get_answer()
get_answer()
作業 repl.it 專案:https ://replit.com/@HarunYilmaz1/AutomaticLightheartedDoom#main.py
uj5u.com熱心網友回復:
isAnswered = False
while not isAnswered:
answer = input("What did you think of this program?")
if answer == 'yes':
print("Thank you! Have a nice day.")
isAnswered = True
elif answer == 'no':
print("Thank you for your feedback, I will try to improve this program")
isAnswered = True
else:
print("Sorry I don't understand, please try again.")
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/411433.html
標籤:
