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

Sean Flanagan
Sean Flanagan
33,235 Points

Repetition

Hi.

My solution keeps asking the same question again and again, whatever the answer.

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

# TODO: Ask the user by name if they understand Python while loops
answer = input(name + ", do you understand Python while loops? \n(Enter yes/no) ")

# TODO: Write a while statement that checks if the user doesn't understand while loops
# TODO: Since the user doesn't understand while loops, let's explain them.
# TODO: Ask the user again, by name, if they understand while loops.
while answer != "yes":
  input("Ok, " + name + ", while loops in Python repeat as long as a certain Boolean condition is met. \n" + name + ", now do you understand Python while loops? \n(Enter yes/no) ")

# TODO: Outside the while loop, congratulate the user for understanding while loops

print("That's great " + name + ". I'm pleased that you understand while loops now. That was getting repetitive.")

3 Answers

Hi Sean,

Your almost there.

In your while loop if you added a print(answer) you are able to see the value of the variable. I do this in my code so can see what happening am sure there is a better way to view variable values as the code runs. This really helps me when am stuck as am learning python at the moment as well.

When the user answers yes or no this variable will not change even if the user enters different value so the code is caught in a loop and so the inequality will not be true.

You would need to return the value again from the input during the while loop.

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

# Ask the user by name if they understand Python while loops
answer = input(name + ", do you understand Python while loops? \n(Enter yes/no) ")

# Write a while statement that checks if the user doesn't understand while loops
# Since the user doesn't understand while loops, let's explain them.
# Ask the user again, by name, if they understand while loops.
while answer != "yes":
    # added to check variable value
    print(answer)
    answer = input("Ok, " + name + ", while loops in Python repeat as long as a certain Boolean condition is met. \n" + name + ", now do you understand Python while loops? \n(Enter yes/no) ")
    # added to check variable value
    print(answer)

# Outside the while loop, congratulate the user for understanding while loops
print("That's great " + name + ". I'm pleased that you understand while loops now. That was getting repetitive.")
nishnash
nishnash
6,267 Points

Don't know what i'm missing here

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

# TODO: Ask the user by name if they understand Python while loops
understand = input(name + ", do you understand python? ")

# TODO: Write a while statement that checks if the user doesn't understand while loops
while understand != "yes":
    print(understand)
    understatnd = input("this is how you use python, do you under stand now? ")
    print(understand)

print(name + " good to know you can use it")
# TODO: Since the user doesn't understand while loops, let's explain them.
# TODO: Ask the user again, by name, if they understand while loops.

Hi nishnash

Made a couple of changes and it seems to work now. There was a typo in one of your uses of 'understand' and the second 'print(understand)' in the while statement appears to be unnecessary. It runs ok like this:

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

# TODO: Ask the user by name if they understand Python while loops
understand = input(name + ", do you understand python? ")

# TODO: Write a while statement that checks if the user doesn't understand while loops
while understand != "yes":
    print(understand)
    understand = input("this is how you use python, do you under stand now? ")

print(name + " good to know you can use it")
# TODO: Since the user doesn't understand while loops, let's explain them.
# TODO: Ask the user again, by name, if they understand while loops.