簡體   English   中英

PYTHON,如何退出一段時間呢?

[英]PYTHON, how to exit a while true?

我是一名剛接觸編程和學習的學生,我正在努力學習Python。 我需要這個循環繼續滾動,直到我點擊屏幕

win=GraphWin("game of life", 600, 600)  
win.setCoords(-1,-3,s+1,s+1)


q = True

while q:

       board = iterate(board)

       x = 0

       while(x<s):
             y = 0
             while(y<s):
                      update_color(x ,y ,board ,rec)
                      y = y+1
             x = x+1
       if(win.getMouse()): # i just tried that, but its not working
              q = False

對不起我的英語不好,這不是我的母語

該代碼基本上檢查用戶是否已經點擊屏幕上的任何地方。

win=GraphWin("game of life", 600, 600)  
win.setCoords(-1,-3,s+1,s+1)


q = True

while q:

       board = iterate(board)

       x = 0

       while(x<s):
             y = 0
             while(y<s):
                      update_color(x ,y ,board ,rec)
                      y = y+1
             x = x+1
       if(win.checkMouse() is not None): #Checks if the user clicked yet
              q = False #Better to use the break statement here

假設http://mcsp.wartburg.edu/zelle/python/graphics/graphics/node2.html是正確的,並且其余代碼都是好的。

將True作為條件可確保代碼運行,直到n.strip()等於'hello'為止。

while True:
    n = raw_input("Please enter 'hello':")
    if n.strip() == 'hello':
        break

關於while循環的Python文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM