G_statements = [["What is 5+5?", "10"],
["What is the square root of 9?", "3"],
["What is 30 / 3", "10"],
["What is 24 x 2", "48"],
["What is 40 / 5", "8"],
["What is 150 - 45", "105"],
["What is 9x9", "81"],
["What is 25+5", "30"]]
# python lists support multi type variables as such ["What is 25+5", 30]
# if you declare the list this way, you can simply do 'if guess == i[1]'
def Generalquiz():
score = 0
# ask a question
for i in G_statements:
print("\n" + i[0])
# try to get a valid (not necessarily correct) answer
while True: # keep asking for a valid input
try: # TRY receiving a valid input
guess = int(input("\nAnswer:")) # try to CAST input to INT, if successful, the input was int, otherwise raise a ValueError
break
except ValueError:
print("Characters not accepted, Please enter a number")
continue # as long as we have an error (that is the input wasn't an int) CONTINUE asking for a valid input
# logic part
if guess == int(i[1]): # correct answer is a string (not the best way, see above comment), convert it to int
score+=1
print("Correct!", score, "out of ", len(G_statements)) # LENgth of G_statements, avoid constant values if possible
else: print("\n\nincorrect!", score, "out of 8\n")
comments should be sufficient for explanation, if you just started to code, try to break the problem into smaller chunks and solve them separately, best of luck!