循环语句失败(Python) [英] Failure in looping a statement (Python)
本文介绍了循环语句失败(Python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
q_3 = raw_input("Choose 1 or 2 or 3") #The question leave 3 options, only one to complete the process
if q_3 == "1":
print ("Wrong!") #Now its wrong number, should start all over again until the user choose 3
elif q_3 == "2":
print ("Wrong") #This is also a wrong number, should start all over again until the user choose 3
elif q_3 == "3":
print ("Correct") #This is now the right number I can handle it from here ! :)
我尝试过:
我尝试while True循环,但我有更多的错误需要处理。
这个想法很简单:3个选项,一个正确...如果错误的答案被选中,那么全部回来再次...如果选择了正确答案,我将raw_input称为另一个问题
What I have tried:
I tried to "while True" loop but I had much more errors to deal with.
The idea is simple: 3 options, one right... if wrong answer picked, back all over again... if right answer picked, I call raw_input for another question
推荐答案
这应该有效:
This should work:
while True:
q_3 = raw_input("Choose 1 or 2 or 3") #The question leave 3 options, only one to complete the process
if q_3 == "1":
print ("Wrong!") #Now its wrong number, should start all over again until the user choose 3
elif q_3 == "2":
print ("Wrong") #This is also a wrong number, should start all over again until the user choose 3
elif q_3 == "3":
print ("Correct") #This is now the right number I can handle it from here ! :)
break
这篇关于循环语句失败(Python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文