我正在編寫Python代碼,它計數到用戶提供的數字,但運行代碼時會進入無限循環。請注意我嘗試了註釋第3行和第4行,並用一個數字替換了「userChoice」,比如說5,並且它工作正常。用戶輸入的python中的無限循環
import time
print "So what number do you want me to count up to?"
userChoice = raw_input("> ")
i = 0
numbers = []
while i < userChoice:
print "At the top i is %d" % i
numbers.append(i)
i = i + 1
print "Numbers now: ", numbers
print "At the bottom i is %d" % i
time.sleep(1)
print "The numbers: "
for num in numbers:
print num
time.sleep(1)
那麼,有沒有,我很想念代碼? –
導致錯誤的輸入是什麼,並且當錯誤發生時您能提供輸出樣本嗎? – SpencerD
如果我選擇任何數字,代碼將無限期地打印+1號 –