此问题已在此处有答案:
Asking the user for input until they give a valid response(22答案)
3小时前关闭
import random
CorrectResponces = ['Congrats', 'Good Job', 'You got it', "You're on fire"]
IncorrectResponces = ['Better luck next itme', 'Think a little harder',
'Wow are you stupid', 'How did you get this one wrong']
FinalResponces = ["You wouldn't even be able to get participation points", 'You are really really bad at this',
"You didn't do absolutely terrible but not good either", "Good enough job ig"]
def True_Or_False():
i = 1
CorrectVal = 0
WrongVal = 0
Start = input('Enter "START" to begin =>')
if Start == "START":
while i <= 3:
VGQuestions = random.randint(1, 3)
if VGQuestions == 1:
Answer = input(
'"The Legend of Zelda Breath of the Wild" Released in 2017 =>')
i = i + 1
if Answer == 'TRUE':
print(random.choice(CorrectResponces))
CorrectVal = CorrectVal + 1
elif Answer == 'FALSE':
print(random.choice(IncorrectResponces))
WrongVal = WrongVal + 1
else:
print('Please enter "TRUE" or "FALSE"')
if VGQuestions == 2:
Answer = input(
'"Super Smash Bros Ultimate" has over 100 playable characters =>')
i = i + 1
if Answer == 'FALSE':
print(random.choice(CorrectResponces))
CorrectVal = CorrectVal + 1
elif Answer == 'TRUE':
print(random.choice(IncorrectResponces))
WrongVal = WrongVal + 1
else:
print('Please enter "TRUE" or "FALSE"')
if VGQuestions == 3:
Answer = input(
'There are over 500 obtainable pokemon across all the games as of 2023 =>')
i = i + 1
if Answer == 'TRUE':
print(random.choice(CorrectResponces))
CorrectVal = CorrectVal + 1
elif Answer == 'FALSE':
print(random.choice(IncorrectResponces))
WrongVal = WrongVal + 1
if WrongVal == 3:
print(FinalResponces[0])
elif WrongVal == 2:
print(FinalResponces[1])
elif WrongVal == 1:
print(FinalResponces[2])
elif WrongVal == 0:
print(FinalResponces[3])
FinalScore = f'Correct {CorrectVal}; Wrong {WrongVal}'
print(FinalScore)
else:
print('Please type "START" to begin')
True_Or_False()
True_Or_False()
我想布尔循环时,'真'或'假'没有输入。我试着把这部分代码放在一个函数中,然后在else之后声明这个函数,但它不起作用。
1条答案
按热度按时间91zkwejq1#