I’m having trouble understand how to add an integer checking function to my program, My program is a simple math quiz that uses numbers from 1-10 and the operators +,-, and division (Questions are randomly generated). The code works fine but in these parts is where it starts to go wrong for some reason
def intcheck(question, low, high):
valid = False
while not valid:
error= "Whoops! Please enter a number between {} and {}".format(low, high)
try:
response = int(input("Enter an integer between {} and {}: ".format(low, high)))
if low <= response <= high:
return response
else:
print(error)
print()
except ValueError:
print(error)
adds the question to questions dictionary
questions.update({question:answer})
Iterates through the questions in the dictionary and response
respectively
for q in questions.keys():
user_answer=input(q)
if questions.get(q)==intcheck(user_answer, -100, 100):
print("Correct!")
score+=1
else:
print("Incorrect")
I want the program to take whatever I put in and if its correct then print correct. If its incorrect and between -100 and 100 print incorrect. If it’s not between -100 (min) and 100 (max) print Make sure your answer is an integer between -100 and 100 and if they don’t enter an integer between -100 and 100 then it will loop until they do. If they do but the input doesn’t = the answer print incorrect, but if they do and the answer is correct then print “Correct”. But this is what happens
When I put a correct answer in
When I put a incorrect answer in
When I put something that isn’t an integer between -100 and 100 in enter image description here
When I put a correct answer in after putting something that wasn’t between -100 and 100 in enter image description here
When I put a incorrect answer in after putting something that wasn’t between -100 and 100 in
I’m a beginner in python and could really use some help.