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.

Python Python Basics Functions and Looping While Loops

Jakub Jeczalik
Jakub Jeczalik
5,379 Points

Running on python 3.6

When running the code in the video, after entering the password 3 times, I do not receive the message "Too many password attempts

1 Answer

Dylan Bailey
Dylan Bailey
574 Points

Hey Jakub! Not sure what's going on with your code, since I can't see it.

If you're not receiving that message, then there's a good chance something is going on with your attempt_count variable.

import sys

MASTER_PASSWORD = "opensesame"
password = input("Please enter the super secret password: ")
attempt_count = 1

while password != MASTER_PASSWORD:
    if attempt_count > 3:
        sys.exit("Too many invalid password attempts!")
    password = input("Invalid password, try again: ")
    attempt_count += 1

print("Welcome to secret town")

Make sure you're nesting your if statement inside of the while loop. And make sure you're incrementing your attempt_count variable at the end of your while loop.