Beginner project question - random Q+A generator

Hello everyone!
I am an entry level beginner going through the “Learning Python” course. I’m about 40% through the course and decided to start a couple small projects just to use what I’ve learned so far.

I am trying to create a math quiz using equations set to random int’s with a random number generator. This is what I’ve got so far:

Here is my issue:
When I run the code, it starts with asking if you want to take the quiz. I type "yes’ and it will generate one of the three equations. When I give an answer, it takes me to the end of the code where it would give me the results.
Screenshot 2023-03-09 044845

How would I get it to continue to generate the rest of the equations? I’ve tried using my “elif” statements as individual “if” statements. I’ve tried putting “continue” after each of the “if” and “elif” blocks.

Thank you for you time!

The issue is that you’re only generating one random number, and then running through the code. In order to get the if statements to run three times (or however many times you want), you’ll need to put them inside a while loop, which will run until all the questions have been answered (and making sure to generate a new random number on each iteration). There will likely be a few issues with just copying the code into a while loop, but they should be quite a good challenge to figure out. If you want any more help, just ask!

1 Like