我創建在用戶已經猜到1和10我的代碼將不會選擇一個新的隨機數
之間的隨機選擇號碼我的代碼工作直至點一個小型項目,其中用戶猜測正確的號碼。它會回到「重新啓動= 1」,但不會生成新的號碼?
下面是我的意思是 - https://gyazo.com/1b6c9afc17997e7a0ee059a8b0eeb89e 的屏幕截圖正如你在這種情況下看到的那樣,數字不會從6變爲?
這將是真棒,有任何幫助可能!
# Useful module for selecting random numbers
import random
# Return to this point when user guesses the correct number
restart = 1
while (restart < 10):
# Variable that chooses a random number
Random_Number = (random.choice([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))
# Loop back to this point
loop = 1
# Checks if users number is correct or not
while (loop < 10):
personStr = input("Guess the random number from 1 - 10?: ")
person = int(personStr)
if person == Random_Number:
print ("You are correct!, the number is", Random_Number)
print ("Try to guess the new number!")
restart = restart + 1
elif Random_Number < person:
print ("Your number is smaller than your selected number, try again!")
loop = loop + 1
else:
print ("Your number is larger than your selected number, try again!")
loop = loop + 1
玩家猜出數字後,你並沒有退出內部循環。只需在增加重新啓動後添加一箇中斷。 –