Apr-22-2020, 01:14 AM
Dictionary would be a good fit for this,so question is key and answer is value.
So it easier to write a example of this than try to fit it this into your code that have some problems.
So it easier to write a example of this than try to fit it this into your code that have some problems.
class Quiz: def __init__(self, questions, score): self.questions = questions self.score = score def quiz(self): keys = self.questions.keys() for quiz_numb, question in enumerate(keys, 1): answer = input(f'{quiz_numb}. {question}') if self.questions[question] == answer: print('Correct answer\n') self.score += 1 else: print(f'Not correct,the answer was <{self.questions[question]}>\n') print(f'Total score for this round {self.score} correct answer') if __name__ == '__main__': # Can come from a external soruce like a simple DB or json questions = { "What is the capital of Colombia? ": "Bogota", "What is the capital of Chile? ": "Santiago" } # Run quiz round_1 = Quiz(questions, score=0) round_1.quiz()
Output:1. What is the capital of Colombia? Bogota
Correct answer
2. What is the capital of Chile? Lima
Not correct,the answer was <Santiago>
Total score for this round 1 correct answer