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
Christopher Morris
iOS Development with Swift Techdegree Student 1,760 PointsNot Understanding Why I can't exit my loop...
name = input("What's your name? ")
question = input("Do you understand Python while loops? ") while (question == "no"): print(input("Do you understand Python while loops? ")) print("Now you get it {}".format(name))
So when i say Yes right away it will exit the loop but once I start saying NO it will loop but then saying Yes will not exit the loop.... idk what i am doing wrong
2 Answers
daltonshanholtz
293 PointsIt'd been quite some time since I have coded Python, but it seems like the loop is never ending because you put the input for the variable "question" in-front of the While Loop. When it asks for the second time/input it seems to not be updating the variable "question". Maybe try fixing that to update the variable or switching the layout a little like this pseduocode:
while answer != no { ask "Do you........etc" };
daltonshanholtz
293 Pointsagain, since it's been awhile this code may be of wrong syntax, but since no others have replied maybe try this?
question = input("Do you understand Python while loops? ") while (question != "yes"): print( question = input("Do you understand Python while loops? ")) print("Now you get it {}".format(name))
Christopher Morris
iOS Development with Swift Techdegree Student 1,760 PointsChristopher Morris
iOS Development with Swift Techdegree Student 1,760 Pointsso that didnt seem to work.. so I have it set up like:
name = input("What's your name? ")
question = input("Do you understand Python while loops? ") while (question != "yes"): print(input("Do you understand Python while loops? ")) print("Now you get it {}".format(name))
So if I say "yes" first... it will kick me to Now you get it... but if I say no first... it will start the loop and the loop will never end :(