少し話題があります:私はPythonでコードを作成しなければなりません。これは、ユーザーが学校プロジェクトの電話機のトラブルシューティングに役立ちます。ユーザーは、プログラムが質問する質問に対してのみ「はい」または「いいえ」と答えなければなりません。無限ループ中Python
私は、「はい」または「いいえ」以外のものを入力すると、一度表示する代わりにループが無限ループするようになり、ユーザーが「はい」と入力すると次の質問に移動します。または 'いいえ'。
コードがまだ完成していないため、いくつかのアドバイスや質問が欠落しているようです。
EDIT:コードは正しく機能します。あなたの答え、みんなありがとう!彼らは本当に役に立ちました!
phoneFault = raw_input("Is your phone physically damaged?")
while phoneFault != "Yes" and phoneFault != "No":
print("Error; you can only answer 'Yes' or 'No' to the questions.")
if phoneFault == "Yes" or phoneFault == "yes":
phoneFault = raw_input("Is your phone wet?")
if phoneFault == "Yes" or phoneFault == "yes":
phoneFault = raw_input("Are you able to turn it off?")
if phoneFault == "Yes" or phoneFault == "yes":
print("Send the phone to the manufacturer and ask if they can fix it.")
elif phoneFault == "No" or phoneFault == "no":
print("Dry the phone, and then wait for the phone to run out of power and then restart it.")
while条件が決して変わらないように、 'phoneFault'の値を決して変更しません。その間に別のphoneFault = raw_input( "Is ...")を追加してみてください。 – dave