Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
In the code,
password = input("please enter a password: ") while password != "opensesame": password = input ("invalid password, try again: ") print ("welcome to secret town")
why doesn't the "welcome to secret town" print, even if i get the wrong password? I thought since theres no if password = opensesame: print welcome ... printing welcome to secret town would work
Cooper Runstein11,836 Points
This happens because your code is in a loop that runs before the print statement. It looks something like this:
get_a_password run_a_loop_until_password_is_correct once_done_with_loop_print_statement
In other words, that loop won't allow the code to continue until the loop exits, in this case, that'll only happen if the password is equal to openseasame (or when the password is no longer not openseasame).