Python Forum

Full Version: I haven't a clue how to implement this logic
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I would like to write a psychology test for the fun of it. It would have ten questions and four multiple choice answers. At the end of the test you could see your score. But the functionality I would like to write into it is the ability to go back to whichever questions the user got wrong and show him what the correct answer was.

I have no clue as to how to do that. One fellow on another forum told me to use a database. But that is not saying much. I would need much more detailed answers.

Please post some suggestions if you have any.
If you have no clue then maybe you are not up to the task.

However, some clues how I would approach the task:

- have questions, multiple choice answers (including correct answer)
- one at the time output question with choices to screen
- save user input (answer)
- after all questions are asked compare correct answers with user answers
- for every correct answer output to screen appropriate information, for non-correct answers output to screen appropriate message along with user answer and the correct answer.
My approach -
Define an Answer class, with the text of the answer, text to be displayed if chosen, flag as to whether this is the right or wrong answer, and flag as to whether this answer was chosen.
Define a Question class, containing the text of the question and containing 4 Answer class items

Instantiate and populate the 40 Answer items and 10 Question items.

Loop through, displaying each question and the text of each answer, asking user to respond. Do validity checks on the responses (if 1-4 don't allow 5 or Moose as responses). Flag the chosen Answer items

When complete, loop through again. If the chosen Answer item is correct, move on. If not, display the response text. During this loop (the grading loop) you can also keep a count of right and wrong answers and give a percent at the end.
(Apr-02-2020, 09:11 AM)perfringo Wrote: [ -> ]If you have no clue then maybe you are not up to the task.

However, some clues how I would approach the task:

- have questions, multiple choice answers (including correct answer)
- one at the time output question with choices to screen
- save user input (answer)
- after all questions are asked compare correct answers with user answers
- for every correct answer output to screen appropriate information, for non-correct answers output to screen appropriate message along with user answer and the correct answer.

I've never done anything like this. My idea was to have the user completely go through the entire test and after the test is over then telling him or her how many questions were answered correctly and then have a Back button and the test would go back to the specific question he or she got wrong and showed them what the correct answer was.

But I think your method would be simpler. That way it's like show correct answer as you proceed through the test.