Aug-31-2022, 03:37 AM
(Aug-30-2022, 05:48 PM)deanhystad Wrote: Dictionaries are not a good choice for your quiz. I can accept this as a dictionary:
{ "question": "What is the capital of France?", "answer": "Paris" }But this should be a list.
quiz = { "question1": {}, "question2": {}, ... }Using "questionN" keys just makes it more difficult to access the questions, and forced you to use items().
I would not use dictionaries for either the questions or the quiz. Since neither the question or quiz change I used tuples.
quiz = ( ("What is the capital of France?", "PARIS") ("What is the capital of Germany?", "BERLIN") ) score = 0 for index, question in (quiz): q, a = question print(f"Question {index+1} : {q}") if input("Answer? ").upper() == a: score += 1 print('Correct!') else: print(f"Incorrect :(\nThe correct answer is: {a}") print(f"Your score is {score}")
Thank you. I like the brevity of code that you implement but I will have to wrap my mind around the logic of its elegance and simplicity