我正在尝试找出如何检查多个字符串的输入例如,足球测验,这里的答案是2003-2004
guess1 = input('which years did Arsenal go unbeaten?')
check_guess(guess1, '2003-2004')
但是如果我想说2003年或2004年都是正确的呢?我在中添加“或”但它不起作用,它将仅接受2003年的第一个字符串,我如何使其接受任一字符串?
guess1 = input('which years did Arsenal go unbeaten?')
check_guess(guess1, '2003') **or** check_guess(guess1, '2004')
这里是完整脚本
#This is a football quiz
def check_guess(guess, answer):
global score
still_guessing = True
attempt = 0
while still_guessing and attempt < 3:
if guess.lower() == answer.lower():
print('You smarty-pants!, correct answer!')
score = score + 1
still_guessing = False
else:
if attempt < 2:
guess = input('You dilly, wrong answer. Try again.')
attempt = attempt + 1
if attempt == 3:
print('This was your last chance, Pal, the correct answer is ' + answer)
score = 0
print('Football quiz!')
guess1 = input('Between which years did Arsenal go unbeaten?')
check_guess(guess1, '2003-2004')
guess2 = input("What is the score of Arsenal's record win against Grimbsy town?")
check_guess(guess2, '9-1')
guess3 = input("Which year marked Arsenal's final game at Highbury?")
check_guess(guess3, '2006')
guess4 = input('Which country won the first ever fifa football world cup in 1930?')
check_guess(guess4, 'Uruguay')
guess5 = input('Who is the top scorer of Arsenal in all time?')
check_guess(guess5, 'Henry')
guess6 = input('How many goals did he score for Arsenal?')
check_guess(guess6, '228')
print('Your score is ' + str(score))
谢谢。
这样定义您的功能:)
猜想这应该做您想要的事情:
您可以使函数执行所需的操作,并通过以下代码使其保持无状态