【发布时间】:2020-01-22 13:17:54
【问题描述】:
嗨,我是 phyton 的新手,我到处找,但我发现的只是多个输入的 .split() 选项,但我不希望它们在一起,我希望在每个单独的 while 循环中都有一个。这就是我到目前为止
基本上我需要做 3 个多个答案的问题,并且“q”持有要测试的答案,如果正确,它会在“pt”中计算一个点,然后“q”重置以用于下一个问题,所以我不会有 3 个变量来完成三个小工作..
q =""
pt = int(0)
print('''\n\n - Answer only with A, B, C Ou D(casing doesn't matter), anything else will be disregarded. \n\n
1-) who would win, Jason Vorhees or Freddy Krugger!? \n A-) Freddy \n B-) Jason \n C-) the Public \n D-) Debatable \n\n
2-) Who is the fastest!? \n A-) Sonic \n B-) speedy \n C-) Flash \n D-) Monica \n\n
3-)Wich boardgame is based on H.P.Lovecraft's stories!? \n A-) Call of Cthulhu \n B-) Sushi Go \n C-) The Resistance \n D-) Arkham Horror \n\n''')
# question 1
while(True):
q = input("answer 1: ")
if(q == "B" or q == "b"):
print("Correct!")
pt= pt+1
break
if(q == "a" or q == "c" or q == "d" or q == "A" or q == "C" or q == "D"):
print('wrong, the correct one is B \n')
break
else:
print("enter a valid letter!!!")
q=""
# question 2
while(True):
q = input("answer 2: ")
if(q == "A" or q == "a"):
print("Correct!")
pt= pt+1
break
if(q == "b" or q == "c" or q == "d" or q == "B" or q == "C" or q == "D"):
print('wrong, the correct one is A \n')
break
else:
print("enter a valid letter!!!")
q=""
# question 3
while(True):
q = input("answer 3: ")
if(q == "D" or q == "d"):
print("Correct!")
pt= pt+1
break
if(q == "a" or q == "b" or q == "c" or q == "A" or q == "B" or q == "C"):
print('wrong, the correct one is D \n')
break
else:
print("enter a valid letter!!!")
q=""
#Final
if(pt>0):
print('You got', pt, 'out of 3 questions right \n')
else:
print('unfortunately you got it all wrong.. not even to look online broh!? :v \n')
【问题讨论】:
-
很抱歉,您不能在两个单独的循环中处理一个输入!如果你仔细想想,你会发现这完全合乎逻辑!
-
那么,问题出在哪里?困惑。
标签: python-3.x input while-loop terminal