Aug-30-2022, 05:45 PM
Some advice can simplify the dictionary be using
then also can remove
Also if using function it look cleaner.
Example.
enumerate()
then no need to hardcode Question1,Question2....,then also can remove
i = 0
.Also if using function it look cleaner.
Example.
def questions(): return { "What is the capital of France?": 'Paris', "What is the capital of Germany? ": 'Berlin', } def quiz(questions): score = 0 for quiz_numb, question in enumerate(questions.keys(), 1): answer = input(f'Question.{quiz_numb}\n{question} ') if questions[question] == answer: print('Correct\n') score += 1 else: print(f'Incorrect the answer was: {questions[question]}\n') print(f'Total score for this round: {score}') if __name__ == '__main__': quiz(questions())
Output:Question.1
What is the capital of France? Paris
Correct
Question.2
What is the capital of Germany? Bern
Incorrect the answer was: Berlin
Total score for this round: 1