返回无效选项的相同测验

时间:2016-11-10 22:51:25

标签: python python-3.x

我正在进行多项选择测验。我希望能够让用户有机会选择有效的选项(a,b或c),以防他们选择不存在的选项(例如e)。我怎么做到这一点?目前,它正好进入下一个测验。

以下是我的部分代码:

def ask_question(question,score):
    choices=('a','b','c')
    print(question[0])
    for multi in question[1:-1]:
        print("{0:>5}{1}".format("",multi))
while True: 
    answer = input("Please select an answer: ")
    if answer == question[-1] and answer in choices: 
        score += 1

    elif answer not in choices:
        print("Incorrect.Try again")
    break

def main():
    questions = get_questions()
    score = 0
    number = 10
    print("Welcome to first quiz!")
    print()

    for next_question in range(number):
        question = random.choice(questions)
        score = ask_question(question, score)
        questions.remove(question)
    print("Your final score was {0} out of {1}.".format(score,number))
    if score >= number * 0.75:
        print("You have passed.")
    else:
        print("You have failed.")
if __name__ == "__main__":
    main()

0 个答案:

没有答案