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

Hello, I put yes and it keeps repeating itself. I dont know what i am doing wrong

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

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

while understand.lower != "yes": print("Ok, {}, while loops in Python repeat as long as certain Boolean condition is met.".format(name)) understand = input(" {} , now do you understand Python while loops?/n(Enter yes/no)".format(name))

print("that's great")

2 Answers

Steven Parker
Steven Parker
231,271 Points

When you call a method (like "lower()"), you must put parentheses after the method name whether it takes argment(s) or not.

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,720 Points

I agree with what Steven Parker says about converting the input-- as a programmer we are trying to anticipate how our program might be used and what sorts of inputs will come in. You can even take it one step further and simply check for the presence of 'yes' in the string.

For example a user could answer 'Yes' or 'YES' or 'Yes I understand' or 'Yes sir!' all these conditions could be handled by the while block your program.

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

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

while not 'yes' in understand.lower():
    print("Ok, {}, while loops in Python repeat as long as certain Boolean condition is met.".format(name))
    understand = input(" {} , now do you understand Python while loops?/n(Enter yes/no)".format(name))

print("that's great")
Steven Parker
Steven Parker
231,271 Points

Testing partial string content with "in" can sometimes produce unexpected results.   :see_no_evil:

program :point_right: Joe , do you understand Python while loops?/n(Enter yes/no)
user    :point_right: no I got confused yesterday
program :point_right: that's great

Constraining the match to just the beginning can help:

while not understand.lower().startswith("yes"):

And for even more flexibility you might check only the first letter ("understand.lower()[0] != "y"), which will match "yes", "YA", "yup", "You bet", "yeppers", etc. :wink: