Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Challenge Solution

Why is it still looping?

That's my code

name = input("What's your name? ")
understanding = input ("{}, do you understand Python while loops?\n Enter yes/no".format(name))

while understanding.lower() != "yes":

    print ("Ok, {} while loops is reapeat until the condition is met".format(name))

understanding = input(" Cool, {} do you now understand while loops? \n Enter yes/no".format(name))

print ("That's great!")

When I answer "no" it never goes to the 2nd question ("Cool, {} do you now...) as it start looping all the time and doesn't stop to show the previous answer ("Ok, {} while loops"). I'm sorry but I don't see what I'm doing wrong :(

Edited: markdown added

3 Answers

Jennifer Nordell thank you so much for your answer and help!

Now I understand that indentation can be crucial :) However, after changes, I'm not sure why it continues to ask me if i understand, so I never get to the final part with congrats.

name = input("What's your name? ")

understanding = input ("{}, do you understand Python while loops?\n Enter yes/no".format(name))

while understanding.lower() != "yes":
    print ("Ok, {} while loops is reapeat until the condition is met".format(name))
    understanding = input(" Cool, {} do you now understand while loops? \n Enter yes/no".format(name))

print ("Congrats, that's great!")

Would you be so kind to take a look again and show me what could be the reason? Thank you <3

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Katarzyna Wójtowicz it does work for me. If I enter "no" the first time and enter "yes" the second time it asks, then I get the "Congrats, that's great!" :smiley:

You are right, I just have been typing "y" instead of "yes"...I'm so sorry for bothering you and again, thank you so much for your help, I deeply appreciate it :)

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Katarzyna Wójtowicz! In a word, indentation :smiley: Both times you ask if the user understands, you're asking outside of the while loop. Which means that it keeps running because the user doesn't get another chance to put in anything else.

Indent this line so that it lines up with the print statement right before it:

understanding = input(" Cool, {} do you now understand while loops? \n Enter yes/no".format(name))

Hope this helps! :sparkles: