-2

Im doing my controlled asessment for my year Computer Science GCSE , but we're not getting graded for it so internet access is permitted. We're supposed to make a 3 topic quiz with 3 different difficulties, 5 questions for each.

Ive come across a problem that I cant seem to solve. When I ask for which difficulty or topic the user would like to take, I added a validation check thing to repeat if they type in something other than the options, however its not repeating, and to add to this it always activates only one option. Eg, they input medium difficulty but easy quiz starts.

The Code:

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

P.s. Im new to this site so if im doing stuff wrong, apologies before hand

Zero Piraeus
  • 56,143
  • 27
  • 150
  • 160
  • 1
    Possible duplicate of [Why does \`a == b or c or d\` always evaluate to True?](https://stackoverflow.com/questions/20002503/why-does-a-b-or-c-or-d-always-evaluate-to-true) – Zero Piraeus Jan 17 '18 at 21:09
  • People are telling you that `if difficulty=="a" or "easy": is wrong Python, it always evaluates to True regardless of the value of `difficulty`. The related duplicate question explains why. – smci Jan 18 '18 at 19:18

2 Answers2

0

not a python expert, but you might need to do if difficulty=="a" or difficulty=="easy":

otherwise what you might actually be testing is if (difficulty=="a") or ("easy" is not zero):

kevin rowe
  • 58
  • 3
0

Use the "in" operator to test multiple conditions;

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

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

>>> a = "m"
>>> a in ("h", "hard")
False

Also (you might find this cleaner);

while True:
   if <condition 1>:
       # do something
   elif <condition 2>: 
       # do something
   elif <user requests program exit>:
       break
   else: 
       print("wrong input, blah, blah ...")
SteveJ
  • 3,034
  • 2
  • 27
  • 47