-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'
,但一次又一次地執行