2016-03-02 56 views
-3

我編寫了一個程序,但我不知道如何循環它。幫助將不勝感激。 這是我需要幫助的程序。使用true和false語句在python中循環整個程序

+5

發佈您的代碼。解釋它做了什麼,以及你期望它做什麼。 – idjaw

+1

您可能想要使用[while循環](https://wiki.python.org/moin/WhileLoop)。 – Phylogenesis

+0

您已經將該程序添加爲圖片。請不要!例如,圖片中的文字不能被複制和粘貼。而現在,圖片的鏈接甚至不可見。所以請編輯您的文章,以便它包含**文本格式的代碼**。要正確格式化,只需選擇整個塊並按下CTRL-K。謝謝! –

回答

-2

你應該做一個程序的功能,這個功能可以放在一個循環中。如需更多幫助,請發佈您的代碼!

0

如果你談論的是一個無限循環(即,必須去和不停止),然後只需使用

white True: 
    <Your code here> 

如果它不是一個無限循環並且只能做到一定值成真則你可以這樣做:

counter = 0 
while counter <= 10: 
    print "This will continue till counter = 10" 
    counter += 1 
1

有兩種類型的循環:indefinite(while)循環和definite(for)循環。如果要循環程序的時間具體數額,然後使用for循環:

for count in range(0, <number of repetitions minus one>): 
    # code 

如果你想循環,直到用戶輸入「退出」或其他一些字符串的程序,使用此:

sentinel = input("Enter QUIT to exit or anything else to continue: ") 
while sentinel.upper() != "QUIT": 
    # code 

下面是一些有用的鏈接教程:

http://www.learnpython.org/en/Loops

http://www.python-course.eu/python3_for_loop.php

http://anh.cs.luc.edu/python/hands-on/3.1/handsonHtml/whilestatements.html#while-statements