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

Kathryn Kassapides
Kathryn Kassapides
9,260 Points

While Loop Challenge. I solved it a different way and it keeps repeating when I answer yes but doesn't give . . .

. . an answer when I answer no. Also, how do you use break. Would a break help with this problem? Here's my code:

name = input("What's your name: ") answer = input(name + ", do you know Python Whiles?")

while answer == 'yes': print("Great job! You know While Loops in Python!!")

if answer == 'no':

    print("Oh No! You gotta learn it!")

1 Answer

Hi Kathryn,

It's hard to say for sure what the issue is without seeing your code with the proper indentation, but I'm assuming your code looks like this:

name = input("What's your name: ")
answer = input(name + ", do you know Python Whiles?")

while answer == 'yes': 
    print("Great job! You know While Loops in Python!!")
    if answer == 'no':
        print("Oh No! You gotta learn it!")

If the above is the way your code is formatted, then the reason you don't get a response when you answer "no" is because the code that handles that is nested inside the while loop, which only runs if answer is equal to "yes", and since answer is "no" the while loop never runs, and python never tests if answer is "no".

If you were to un-indent the if statement in the above example I've written, then run the program, and enter "no" to the "do you know Python Whiles?" question, then "Oh No! You gotta learn it!" should be printed in the console.