Python Forum
Pointer in the right direction?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pointer in the right direction?
#5
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.
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
Reply


Messages In This Thread
Pointer in the right direction? - by Viking - Apr-21-2020, 07:57 PM
RE: Pointer in the right direction? - by deanhystad - Apr-21-2020, 08:00 PM
RE: Pointer in the right direction? - by Viking - Apr-21-2020, 08:24 PM
RE: Pointer in the right direction? - by deanhystad - Apr-21-2020, 08:47 PM
RE: Pointer in the right direction? - by snippsat - Apr-22-2020, 01:14 AM
RE: Pointer in the right direction? - by Viking - Apr-22-2020, 06:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Project Direction bclanton50 1 1,382 Jan-06-2022, 11:38 PM
Last Post: lucasbazan
Question How to understand the vector/direction mason321 0 1,164 Dec-14-2021, 10:57 PM
Last Post: mason321
  General pointer to start data4speed 3 2,046 Jul-01-2020, 06:18 AM
Last Post: DPaul
  Length and direction cosines of lines tarikrr 1 1,816 Nov-15-2019, 04:16 AM
Last Post: SheeppOSU
  Some direction needed Patriot1017 3 2,566 Sep-03-2019, 05:44 PM
Last Post: jefsummers
  Practicing using a "flag": please point in right direction magsloo 5 3,218 May-10-2019, 04:58 AM
Last Post: perfringo
  VM address (C pointer) of Python object Skaperen 1 2,104 Apr-21-2019, 10:57 PM
Last Post: hshivaraj
  trace invalid pointer simon149 7 5,269 Apr-16-2019, 07:05 AM
Last Post: simon149
  How to create a graph for direction visualization Visiting 2 2,844 Sep-22-2018, 10:49 PM
Last Post: Visiting
  Need tutorial/direction to access shared memory ridshack 2 3,084 Feb-22-2018, 11:24 PM
Last Post: ridshack

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020