📜  在python中如何在10次输入后结束代码 - Python代码示例

📅  最后修改于: 2022-03-11 14:45:03.020000             🧑  作者: Mango

代码示例1
incorrect = 0
max_tries = 3
choices = ['red', 'green', 'yellow']

while incorrect < max_tries:
    user_input = raw_input()
    if user_input not in choices:
        incorrect += 1
    else:
        rest_of_the_code(user_input)
        incorrect = 0

if incorrect == max_tries:
    sys.exit(1)