使用下面的代码它对我有用。
def check_guess(guess, answer):
global score
global name
still_guessing = True
attempt = 0
while still_guessing and attempt < 3:
if guess == answer:
print('Correct wow, i expected worse from someone named %s' % name)
if attempt == 0:
score = score + 3
elif attempt == 1:
score = score + 2
elif attempt == 2:
score = score + 1
still_guessing = False
elif attempt <= 2:
print('HAAAAAAAAAAAAAAAAAAAAAAAAAAAA IMAGINE NOT GETTING THAT RIGHT!!!')
print('L bozo + ratio')
guess = input('Try again ')
attempt = attempt + 1
if attempt == 3:
print('the correct answer was %s' % answer)
print('There is always next time!!')
still_guessing = False
score = 0
print('Welcome to the animal quiz')
print()
print('In this game you will have to guess the animal')
name = input('What is your name? ')
print('Cool name, I feel like i heard of it before hmmm %s..' % name)
print()
print('Enough stalling onto the game!!!')
guess1 = input('Which bear lives in the north pole ')
check_guess(guess1.strip().lower(), 'polar bear')