2012-12-11 48 views
1

當然有一種方法,但我不知道它。任何人都可以啓發我如何反覆運行一段代碼,直到一個變量等於另一個變量。基本上我正在寫一個簡單的程序,隨機產生兩個數字,並不會停止,直到兩個數字相等。我知道,這只是一個簡單而毫無意義的程序,但知道這將幫助我進一步編程。(PYTHON)直到a == b

謝謝!

+0

你正在尋找一個[while循環(http://en.wikipedia.org/wiki單程/ While_loop)(帶有否定循環條件) – moooeeeep

回答

5

這裏的

n1 = 0 
n2 = 1 
while n1 != n2: 
    n1 = my_random_function() 
    n2 = my_random_function() 

while True: 
    a = random_function() 
    b = random_function() 
    if a == b: 
     break 
+0

非常感謝,幫助了很多! – MalyG

3

while a != b: 
    # do stuff 
+0

謝謝,但其他人毆打你,所以我給他/她的答案。仍然投票你的有用的! – MalyG

相關問題