I would like to know how to add user input to this code so the user can choose the topic (there will be more topics added) and difficulty instead of it having to be called at the bottom. Any explanation is much appreciated as I am quite poor with user input.
from collections import namedtuple
Question = namedtuple("Question", "question answer choices correct")
maths_questions = [Question("What is 1 + 1", "1 + 1 is 2", ["1", "2", "3", "4"], {"b", "2"}),
Question("What is 2 + 3", "2 + 3 is 5", ["5", "4", "2", "1"], {"a", "5"})]
ansdict=[]
def quiz(questions, difficulty):
score = 0
for question in questions:
global ansdict; ansdict = question.choices
print(question.question)
output(difficulty, ansdict)
users_answer = input().lower()
if users_answer in question.correct:
print("Correct")
score += 1
else:
print("Incorrect", question.answer)
print("{} out of {}".format(score, len(questions)))
def output(difficulty, dicti):
for i in range(difficulty):
print(dicti[i])
quiz(maths_questions, 4)