我注意到一些错误。
首先,您不需要if-trument==3或2,因为您使用的是while循环(while循环基于最初的条件)。
第二,最好将“break”积分为一个无限循环。
而循环从0开始,在2结束(取3个值)。
我为你重写了代码。
def check_guess(guess, answer):
global score
global name
still_guessing = True
attempt = 0
while still_guessing and attempt < 2:
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 <= 1:
print('HAAAAAAAAAAAAAAAAAAAAAAAAAAAA IMAGINE NOT GETTING THAT RIGHT!!!')
print('L bozo + ratio')
guess = input('Try again ')
attempt = attempt + 1
break
print('the correct answer was %s' % answer)
print('There is always next time!!')
still_guessing = False
要测试代码,请添加
print("pass OK")
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')
print("pass OK")
别忘了投票:)(斋月卡里姆!!!)