#๐Ÿ”’ While loop not working

22 messages ยท Page 1 of 1 (latest)

verbal trench
fleet cairnBOT
#

@verbal trench

Python help channel opened

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.

verbal trench
#

Im not sure what to do, im new to python

golden abyss
#

What doesn't work?

verbal trench
#

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 :(

golden abyss
#

Also provide full code including

  • Where you define maths_question
  • Where you define m_options, m_answers
verbal trench
golden abyss
#

Oh wait

#

I know why now

verbal trench
#

:)

golden abyss
#

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
verbal trench
#

ok!

hardy solar
# verbal trench 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

verbal trench
#

K

fleet cairnBOT
#
Python help channel closed for inactivity

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.