I am trying to create a math game where it randomly chooses a question from my list and gives the corresponding answer. At the moment, I can get the questions to randomise however, it gives the answer in order from the list, not the answer corresponding to the question. How do I get the answer to be correct to the random question. Here is my code.
import random
counter = 0
score = 0
incorrect = 0
name=input("What is your name?")
print("Hi",name,",welcome to your math quiz!")
questions = ["10*2","4-2","6+12","6*4","12-5","6+54","1*0","3-6","4+0","65-9"]
answers=["20","2","18","24",'7','60','0','-3','4','56']
idx_questions = list(enumerate(questions))
idx_answers = list(enumerate(answers))
random.shuffle(idx_questions)
for idxq, question in idx_questions:
print(question)
ans = input("What is the answer? ")
for idxa, answer in idx_answers:
if idxq == idxa and ans == answer:
print("Correct")
score=score+1
print("Correct Answers=",score)
print("Incorrect Answers=",incorrect)
elif idxq == idxa and ans != answer:
print("Incorrect", answers)
incorrect=incorrect+1
print("Correct Answers=",score)
print("Incorrect Answers=",incorrect)
print("End of quiz")
print(name,"your score is",score,"out of 10")
print(score*10,"%")