2015-10-06 38 views
-2

所以基本上這是我的學校作業我們一直在Python上編寫一個小測驗使用空閒我試着給Rerty添加一個循環如果你做得不好,但是當你輸入0時爲了關閉它應用程序就像它應該做的那樣關閉,但是當我將1放到Rerty時,它會一遍又一遍地重新執行相同的命令,並且不會重新開始測驗。這是腳本。當我在Python中輸入循環命令時,它不遵循語句?

the screenshot of the Script

+0

使您的問題更具可讀性。例如添加更多標點符號.. – Vova

回答

1

現在你只需要在那裏問他們,如果他們想再次嘗試部分腳本循環,它沒有辦法控制流動回升到年初,並要求所有的問題。

考慮改變與函數定義

def quiz(): 
    # code that asks questions goes here 
    # show them their score ask if they want to go again 
    if yes: 
     quiz() # restart the function within itself (recursion) 
    else: 
     print ("okay bye") 

quiz() # this is the first call that gets it all started 
0

循環重新開始,其中while語句是流量。眼下,因爲程序將測驗不重複測驗,然後被捕獲退出

answer.lower().startswith("0") 
    exit() 

,只是重複循環,而這又只給出了選擇退出或重複循環之間。它重複循環,因爲你告訴它打印ok, carry on then然後開始回到while

所以測驗獲取運行每次while循環重新開始,您可以將測驗本身while循環中。

while True: 
    QUIZ 
    quit = input('Retry or quit?') 
    if quit: 
     exit() 
    elif not quit 
     whatever you want to say here, the program won't exit so it starts back at the while