Search code examples
pythontimer

(Python) Make a timer and skip code when timer runs out


I want to make a quiz (5 questions) in which a timer (50 seconds) is running. The quiz should end either when the time is up or the user answers all questions.

I am pretty new to the coding world, but I already made the quiz (in German) with if, elif, else. So, the only thing is that I have no idea how to make the timer and make it skip other questions if the user is too slow.


Solution

  • It is hard to answer without seeing your code. But if you set up a timer:

    https://www.udacity.com/blog/2021/09/create-a-timer-in-python-step-by-step-guide.html#:~:text=To%20create%20a%20simple%20timer,each%20component%20inside%20the%20module.

    As the user answers the quiz you can store his answers in a dict_of_answers = {}. By adding it dict_of_answers[question_number] = answer.

    At the end of the timer you can call the function that loads the result of the quiz by checking what is the current answers you have in dict_of_answers