私の目標は: 私は現在、簡単なトラブルシューティングプログラムを構築しようとしています。変数current_questionは、ネストされたif文に沿った各入力/質問の値として更新されることを意図しています。これは、コードが現在質問している質問を識別できるようにするためです。その結果、私は戻って、ユーザが間違ったデータを入力する場合には、現在の質問にループすることができます(ないそうではなくなし)python whileループ、変数current_questionが更新されていません
問題 しかし、私は、コードをテストし、それが2番目の質問への継続した場合、この変数は質問2,3,4に更新されませんが、私は間違ったデータを入力するたびに最初の質問だけでループが動作します。私はこれを長い間解決しようとしてきましたが、解決策にはまだ達していないので、これは始めるのに適していると思いました。
コード!あなたの意図はないだろう、すべての可能な質問if-elif
のためのループにある場合
import time
current_question =()
i = 1
while i <= 4:
q1 = str(input('Is your phone wet? ')).lower()
current_question = q1
i = i + 1
if q1 == 'yes' or q1 == 'Yes':
print('dry it out')
break
elif q1 == 'no' or q1 == 'No':
q2 = str(input('is your phone cracked? ')).lower()
current_question = q2
i = i + 1
if q2 == 'yes' or q2 == 'Yes':
print('replace screen')
break
elif q2 == 'no' or q2 == 'No':
q3 = str(input('are you able to download apps/videos? ')).lower()
current_question = q3
i = i + 1
if q3 == 'yes' or q3 == 'Yes':
print('delete any apps or videos that you don\'t need')
break
elif q3 == 'no' or q3 == 'No':
q4 = str(input('Is your phone unresponsive? ')).lower()
current_question = q4
i = i + 1
if q4 == 'yes' or q4 == 'Yes':
print('restart it')
break
elif q4 == 'no' or q4 == 'No':
print('contact the supplier')
break
while current_question != 'yes' and current_question != 'no':
print('try again')
time.sleep(1)
print(current_question)
にユーザーがあなたを与える応答を 'current_question'変数を設定している、ありますあなたは何をするつもりでしたか? –
あなたの最後のwhileループでも 'current_question'の値を決して変更していないので、無限ループです – Keiwan
あなたはあなたがどのような質問をしているか追跡する方法を探しているかもしれません(http: /stackoverflow.com/a/18863481/5827215) –