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

Daniel McCann
PLUS
Daniel McCann
Courses Plus Student 5,308 Points

if no is entered as first answer my yes response does not break the loop and it continues to ask me if i understand

I am thinking my error is something small?

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


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

while understand.lower() != "yes":
    print("Okay, {} while loops repeat a block of code as long as a certain Boolean condition is met. ".format(name))
    input("Do you understand now {}? ".format(name))

print("congrats on understanding while loops!")

3 Answers

Your loop checks variable understand each go round, but understand is not updated within the loop so the condition never changes. Therefore you end up in an infinite loop. Make the following modification so that understand is updated within the loop:

 understand = input("Do you understand now {}? ".format(name)) 
Aimable RUHUMURIZA
Aimable RUHUMURIZA
1,806 Points
name = input("What's your name? ")

# TODO: Ask the user by name if they understand Python while loops

understandPython = input("{},Do you understand Python while loops ... YES/NO : ".format(name))

# TODO: Write a while statement that checks if the user doesn't understand while loops
while understandPython.lower() != 'yes' :
# TODO: Since the user doesn't understand while loops, let's explain them.
  print("Ok, {}, while loops in Python repeats as long as certain Boolean condition is met".format(name))
# TODO: Ask the user again, by name, if they understand while loops.
# Here is where you need to pay attention. understandPython variable needs to be given value again
  understandPython = input("{},Do you understand Python while loops ... YES/NO : ".format(name)) 
# TODO: Outside the while loop, congratulate the user for understanding while loops
print("Congratulation {}, I'm pleased that now you understand while loop".format(name))
Brendan Berg-Jacobson
Brendan Berg-Jacobson
1,067 Points

Hi all, I'm having the same problem they did. It repeats and never ends with the congratulation. I can't figure out what I'm doing wrong. Please help. my code is below. Thank You! https://w.trhou.se/lte9tjtuds