[問題] 自學新手的一個問題

看板Python作者 (JIMMY)時間12年前 (2012/01/22 22:36), 編輯推噓0(003)
留言3則, 3人參與, 最新討論串1/1
number = 23 running = True while running: guess = int(raw_input('Enter an integer : ')) if guess == number: print 'Congratulations, you guessed it.' running = False # this causes the while loop to stop elif guess < number: print 'No, it is higher than that.' else: print 'No, it is lower than that.' else: print 'The while loop is over' print 'Done' 請問 在running = False # this causes the while loop to stop 這邊會讓迴圈停止 為什麼啊?? 麻煩各位高手為小弟解惑 順便一問PYTHON 的學習手冊有二手或那裡租的到嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.45.87.106

01/22 22:41, , 1F
while 後面的陳述為 False 時, 會跳出 while block
01/22 22:41, 1F

01/23 23:39, , 2F
設定成False之後,下次執行到迴圈判斷就會跳出迴圈
01/23 23:39, 2F

01/24 11:42, , 3F
了解了 謝謝
01/24 11:42, 3F
文章代碼(AID): #1F71xb2_ (Python)