Skip to the content

Project: password checker

Python · Unit 6: Strings

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. 1. Write the code

    A safe password has at least one digit. Write has_digit(password), which returns True if some character is a digit and False if none of them is.

  2. 2. Find the bug

    has_upper should say whether the password has a capital letter. With "hellO" it should print True. Which line has the error?

  3. 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".

Do this lesson

It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.

See all lessons →