#๐ While loop not working
22 messages ยท Page 1 of 1 (latest)
@verbal trench
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Im not sure what to do, im new to python
What doesn't work?
This is a code for quiz and everytime you got a question wrong, your life will -1 but when the life is smaller than 0 the while loop didn't stop :(
Also provide full code including
- Where you define
maths_question - Where you define
m_options,m_answers
Can you show the execution?
:)
You run for loop in while loop
So it would only end when you complete the entire set of questions
If you have no life left
And if you have, it repeat again
A simple work around
At the end of the for loop (indent level 2)
Add
if life <= 0: # Indent level 2
break #indent level 3
ok!
tysm, it works now :)
no need for the while loop now unless you want them to redo all the questions and in that case you can just do while True: as you are already checking the number for lives left after each answer, but you probably want to reset the number of lives and the score before the next run through then as well
K
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.