Unit 6 · Class is in Session · Lesson 51 of 57
Project: Lockout
Project time!
Remember cracking Alex's PIN by trying all 1000 of them? The fix was to lock people out after a few wrong tries.
Let's build that, properly this time, with a class.
What it should do
Make a class called Account:
__init__(self, username, password)
- stores the
usernameandpassword - starts
self.attemptsat0 - starts
self.lockedasFalse
login(self, password) returns one of three strings:
So for an account with the password purple4life:
amer = Account("amer", "purple4life")
amer.login("amer123") # "Wrong"
amer.login("amer1234") # "Wrong"
amer.login("amer12345") # "Wrong" (and now it's locked)
amer.login("purple4life") # "Locked" (too late, Amer)
Once it's locked, even the right password gets
"Locked". That's the whole point!
Build the Account class!
Python exercise
Write the program in an editor next to the lesson, run it, and have it checked automatically. Create a free account to do this part.
Do this lesson for real
With a free account you get the terminals, challenges and checks that go with the lessons in Intro to Python, and your progress is saved as you go. CyberAcad is a 501(c)(3) nonprofit, so there is nothing to pay.