如果传递了特定的输入,则尝试立即重新启动方法,并跳过代码结尾

时间:2019-03-17 00:11:20

标签: python

我对python还是很陌生,如果输入不正确(e-z中的任何字母,包括e和z),我都试图实现强制重启功能

from Question import Question

incorrect_input = False
incorrect_final = False
exit_test = False
question_prompts = [
    "What colors are pears?\n(a) Red\n(b) Blue\n(c) Green\n(d) Yellow",
    "What colors are bananas?\n(a) Yellow\n(b) Blue\n(c) Green\n(d) Red",
    "What colors are apples?\n(a) Blue\n(b) Yellow\n(c) Red/Green\n(d) Orange"
]

questions = [
    Question(question_prompts[0], "c"),
    Question(question_prompts[1], "a"),
    Question(question_prompts[2], "c")
]


def exec_test(questions):
    score = 0
    incorrect_input = False
    incorrect_final = False
    exit_test = False
    for question in questions:
        answer = input(str(question.prompt) + "\nEnter your answer: ")
        if answer == question.answer and answer.lower() not in "efghijklmnopqrstuvwxyz":  # incorrect input check
            print("Correct Answer!\n")
            score += 1  # increments score by one if correct
        elif answer != question.answer and answer.lower() not in "efghijklmnopqrstuvwxyz":  # incorrect input check
            print("Incorrect Answer!\n")
        else:
            print("You entered an incorrect form of input! Try again.\n")
            incorrect_input = True  # sets a boolean to True which eventually restarts the quiz
            incorrect_final = True
            exit_test = True
            return incorrect_final
    if exit_test is True:
        return None
    if incorrect_final is True:
        exec_test(questions)
    print("Final Score: " + str(score) + "/" + str(len(questions)) + " correct!")  # final score output


exec_test(questions)

如何让它放弃所有先前的测验答案,并在通过不必要的输入时重新启动方法?

1 个答案:

答案 0 :(得分:1)

使用map.getZoom()

map.setZoom(18)