-2
该代码允许我输入六次以上,也没有打印else
声明。我的代码是:随机密码的代码
import random
secret = random.randint(1, 99)
guess = 0
tries = 0
print ('AHOY! I am the Dread Prites Roberts , and i have a secret!')
print ('It is a number from 1 to 99. I\'ll give you 6 tries ')
while guess != secret and tries < 6:
guess = int(input('What is your guess? '))
if guess < secret:
print ('Too Low, you scurvy dog!')
elif guess > secret:
print ('Too high, boy')
tries = tries + 1
elif guess == secret:
print ('Avast! you got it ! Found my seceret , you did!')
else:
print ('No more guess! Better Luck next time')
print ('The secret number was',secret)
我试过了Python 3.4中的代码。它打印结果超过六次。虽然猜不等于秘密,并尝试... 6次尝试后,它会打印'No more guess better luck next time'
,但一次又一次地执行