我从python开始。当我在if语句中放入一个新的raw_input时,我一直收到错误。如果他们回答的输入不正确,我想给他们另一个输入更多输入的机会,还有另外一种方法吗?
继承守则
attraction = {
'approach' : "words",
'introduction' : "words",
'qualification' : "words",
'rapport' : "words"
}
answer = raw_input("Pick from these approaches: introduction, qualification, or rapport:")
if answer != "approach" and answer != "introduction" and answer != "qualification" and answer != "rapport":
new_answer = raw_input("You didn't choose one of the choices, type in the choice you want again:")
if new_answer != "approach" and answer != "introduction" and answer != "qualification" and answer != "rapport":
print "That was your last chance buddy"
else:
print attraction[answer]
答案 0 :(得分:2)
当您第二次询问时,您无需制作新变量new_answer
,只需将answer
设置为新值:
answer = raw_input("You didn't choose one of the choices, type in the choice you want again:")
将[{1}}替换为程序中其他地方的new_answer
。
我会使用answer
方法执行此类程序:
.keys()
答案 1 :(得分:0)
您可以简单地写一下:
while True:
answer = raw_input("Pick from these approaches: introduction, qualification, or rapport:")
if answer == "approach" or answer == "introduction" or answer == "qualification" or answer == "rapport":
break