代碼工作正常,但我無法弄清楚如何完全重新啓動程序。我繼續在代碼中,並且我知道這是不正確的,因爲我希望它在您猜到正確的數字後完全重新啓動,並顯示'恭喜!你猜猜我的電話號碼。Python隨機數生成器
import random
guesses = 0
number = random.randint(1, 100)
print('I am thinking of a number between 1 and 100.')
while guesses < 100:
guess = int(input('Guess? '))
guesses = guesses + 1
if guess < number:
print('Your guess is too low.')
if guess > number:
print('Your guess is too high.')
if guess == number:
continue
if guess == number:
guesses = str(guesses)
print('Congratulations! You guessed my number in ' + guesses + ' guesses!')
只是把整個東西放在一個while循環像「while True」,然後問他們是否他們如果答案不是,請繼續並中斷 – gkusner
感謝您的幫助,此解決方案可以工作,但我希望程序自動重啓。 – Aaron