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

while

name=input('whats your name? ') answer=input(f'{name} do you understand while loops? ') while answer!='Yes' or 'yes': print('while loops blablabla') input('and now? ') else: print('good for you')

why does it print 'while loops blablabla' when i type yes?

2 Answers

Steven Parker
Steven Parker
243,656 Points

The logical operator "or" should be used with complete comparison expressions. A non-empty string is "truthy" by itself, so adding "or "yes"" to any comparison will make the whole expression always True.

Plus, combining two inequalities will also always be "True", since one or the other will always not match. So you probably want to combine those tests using "and" instead:

while answer!='Yes' and answer!='yes': 

And you can make it a bit more compact by using case conversion and just one comparison:

while answer.lower() != 'yes': 

thanks :)