print("Mathematics Quiz")
question1 = "What is the square root of 16?"
options1 = "a. 4\nb. 6\nc. 2\nd. 16\n"
options2 = "a. Chang'e\nb. Hou Yi\nc. Jing Wei\nd. Susano\n"
question2= "Who is the Chinese God of the sun?"
print(question1)
print(options1)
validinput = ("a" and "b" and "c" and "d")
# Attempts = 2 per question
while True:
response = input("Hit 'a', 'b', 'c' or 'd' for your answer\n")
while response is not validinput:
print("Please use a valid input")
break
else:
if response == "a":
print("Correct! You Got It!")
break
elif response == "b" or "c" or "d":
print("Incorrect!!! Try again.")
while True:
response = input("Hit 'a', 'b', 'c' or 'd' for your answer\n")
if response == validinput:
print("Correct! You Got It!")
stop = True
break
else:
print("Incorrect!!! You ran out of your attempts!")
stop = True
break
if stop:
break
So, This is code for a simple little quiz, and it works if I don't include the valid/invalid input part. So what i'm trying to accomplish is to make it so if the user input is anything other than "a" "b" "c" or "d" then it will return "Please use a valid input" and loop until a valid input is used. I believe the problem may be with the way i defined "validinput". For whatever reason, "a" is the only accepted input while all others make the program return with "Please use a valid input". Anyways it would be much appreciated if anyone knew how to either fix this or had a different idea altogether. Thanks!