亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在每個循環中打印列表的不同元素?

如何在每個循環中打印列表的不同元素?

慕尼黑的夜晚無繁華 2024-01-15 17:04:03
我正在制作一個測驗程序,用戶可以在測驗中添加任意數量的問題,并且他們也可以參加測驗。我只是不知道如何單獨打印問題。questionsList = [] rightAnswersList = []choicesList = []while True:    option = int(input("Add questions or take the quiz? 1 or 2 respectively: "))    if option == 1:       # adds a question to questionsList and choices to choicesList and answers to rightAnswersList     elif option == 2:       # prints question1 --> choices --> asks answer then it loops so question2 and its choices will now be printed
查看完整描述

1 回答

?
呼啦一陣風

TA貢獻1802條經驗 獲得超6個贊

我不確定你想要什么,但這滿足了你的評論所要求的最低限度:


questionsList = [] 

rightAnswersList = []

choicesList = []

while True:

  option = int(input("Add questions or take the quiz? 1 or 2 respectively: "))

  if option == 1:

    questionsList.append(input("Enter question: "))

    choices = []

    while True:

      choice = input("Enter answer choice or enter 'q' to exit: ")

      if choice == "q":

        break

      choices.append(choice)

    choicesList.append(choices)

    rightAnswersList.append(input("Enter answer: "))

  elif option == 2:

    for i in range(len(questionsList)):

      print(questionsList[i])

      print("Choices:\n" + "\n".join(choicesList[i]))

      answer = input("Enter your answer: ")

      print("Your answer is: " + answer)

      print("Correct answer is: " + rightAnswersList[i])

您可能需要添加額外的代碼來過濾用戶輸入或檢查用戶答案。


查看完整回答
反對 回復 2024-01-15
  • 1 回答
  • 0 關注
  • 131 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號