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

我正在制作一个测验程序,用户可以在测验中添加任意数量的问题,并且他们也可以参加测验。我只是不知道如何单独打印问题。


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



慕尼黑的夜晚无繁华
浏览 94回答 1
1回答

呼啦一阵风

我不确定你想要什么,但这满足了你的评论所要求的最低限度: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])您可能需要添加额外的代码来过滤用户输入或检查用户答案。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python