Python 验证程序不起作用

Python 验证程序不起作用,python,python-3.x,Python,Python 3.x,我正在为我今年的计算机科学GCSE做控制评估,但我们没有得到评分,所以允许上网。我们应该做一个3个主题的测验,有3个不同的困难,每个有5个问题 我遇到了一个我似乎无法解决的问题。当我询问用户希望采用哪种难度或主题时,我添加了一个验证检查内容,如果他们输入了选项以外的内容,则重复该内容,但它不会重复,并且为了添加该内容,它始终只激活一个选项。例如,他们输入中等难度但简单的测验开始 守则: check=False while check==False: difficulty=input("W

我正在为我今年的计算机科学GCSE做控制评估,但我们没有得到评分,所以允许上网。我们应该做一个3个主题的测验,有3个不同的困难,每个有5个问题

我遇到了一个我似乎无法解决的问题。当我询问用户希望采用哪种难度或主题时,我添加了一个验证检查内容,如果他们输入了选项以外的内容,则重复该内容,但它不会重复,并且为了添加该内容,它始终只激活一个选项。例如,他们输入中等难度但简单的测验开始

守则:

check=False
while check==False:
    difficulty=input("What difficulty would you like to use?\nA-Easy\nB-Medium\nC-Hard") #\n drops down a line
    if difficulty=="a" or "easy":
        print("Easy mode turned on")
        check=True
        easy_quiz() #function written before hand
    elif difficulty=="b" or "medium":
        print("medium mode turned on")
        check=True
        medium_quiz() #function written before hand
    elif difficulty=="c" or "hard":
        print("Hard mode turned on")
        check=True
        hard_quiz() #function written before hand
    else:
        print("error, wrong input, please try again.") # Here is where i Thought it should repeat the question at the top

另外,我是这个网站的新手,所以如果我做错了什么事,请先道歉

不是python专家,但你可能需要这样做 如果难度==a或难度==容易:

否则,您实际上可能要测试的是
如果难度==a或easy不是零:

使用in操作符测试多个条件

>>> a="hard"
>>> a in ("h", "hard")
True

>>> a = "h"
>>> a in ("h", "hard")
True

>>> a = "m"
>>> a in ("h", "hard")
False
你也可以找到这种清洁剂

while True:
   if <condition 1>:
       # do something
   elif <condition 2>: 
       # do something
   elif <user requests program exit>:
       break
   else: 
       print("wrong input, blah, blah ...")
可能有重复的人告诉您,如果难度==a或easy:是错误的Python,那么无论难度的值是多少,它的计算结果总是为True。相关的重复问题解释了原因。