Project: password checker
Python · Unit 6: Strings
- Full plan
- Python
- Project
- 3 exercises
For this project there are two more methods: isdigit() says whether a character is a digit and isupper() whether it is a capital.
Both return True or False.
print("7".isdigit())
print("a".isdigit())
print("M".isupper())
print("m".isupper())Prints
True False True False
The rest of the explanation is in the lesson, which is part of the full plan.
Exercises in this lesson
You do them in the app, which checks them on the spot and explains why.
1. Write the code
A safe password has at least one digit. Write
has_digit(password), which returnsTrueif some character is a digit andFalseif none of them is.2. Find the bug
has_uppershould say whether the password has a capital letter. With "hellO" it should printTrue. Which line has the error?3. Write the code
Write
check(password)using the two functions you already have. Return the first message that applies, in this order: with fewer than 8 characters,"Short: N/8", where N is its length; with no digits,"Needs a digit"; with no capitals,"Needs a capital"; if it passes everything,"Strong".
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.