當我將代碼放入一個循環中,並且第二次運行它時,它說列表中沒有任何內容。無論如何,我可以重置該列表中的內容,以便在代碼再次運行時,列表中的所有內容都會重新顯示?我已經檢查了其他問題,但他們的解決方案似乎不起作用。.pop和空列表的問題
global questions
questions = [class_question, color_question, life_question, vacation_question, patronus_question, skills_question, friends_question, values_question, pet_question]
def nextpart():
user_interface()
(questions.pop(0))()
turtle.onscreenclick(shapedrawer)
turtle.listen()
def quiz_loop():
reply = raw_input("Do you want to take a quiz? Type Y for yes or N for no, lowercase.")
while reply == "y":
beginning()
nextpart()
print ("")
reply = raw_input("Unsatisfied with the house you got? \n Type Y to retake the quiz or N to end this program. \n Make sure that you use lowercase letters.")
if reply == "n":
print ("Okay, bye! Thanks for playing.")
else:
print ("I hope you enjoyed your experience.")
在您未顯示的某些代碼中,是否將'nextpart'設置爲來自'turtle'模塊的回調?目前還不清楚'quiz_loop'中的'while'循環是否應該迭代這些問題,或者它只是調用'nextpart'來啓動另一個不太明顯的循環。無論如何,我猜想使用迭代協議(無論是'for'循環還是手動調用'iter'和'next')可能比用'pop'銷燬列表更好。我不確定如何將該建議轉化爲答案,因爲我不太瞭解您的代碼。 – Blckknght