🐍 [Day 1] check_password()

April 20, 2026

Morning! πŸ˜ƒ β˜•οΈ

Every time you make an account, something behind the screen looks at your password and decides: weak, medium, or strong.

This week, you're going to be that something. You'll learn one small, real Python function - check_password() - that reads a password and returns exactly that verdict.

Here's how the week works: today you see the whole function. Each morning after, a few lines quietly disappear. By Friday only the bones are left and you fill in the rest from memory. No flashcards, no drills - you just keep the function.

In today's email...

THE FUNCTION 🐍

def check_password(password):
    if len(password) < 8:
        return "Weak"
    has_number = False
    for char in password:
        if char.isdigit():
            has_number = True
    if has_number:
        return "Strong"
    return "Medium"

The full check_password() function shown in a dark code editor window with numbered lines 1 to 10 and Python syntax highlighting

Ten lines. That's the whole week. Keep this card - the line numbers on it are the ones we'll use every morning.

TODAY'S LINE πŸ’­

Nothing is blanked yet - so today let's walk the whole flow once, top to bottom.

def check_password(password): gives the function a name and says "hand me a password to look at."

The first check is a shortcut: if len(password) < 8: asks "is it shorter than 8 characters?" If so, it's "Weak" - and return stops the function right there. Nothing else needs to run.

If it survives that, we look for a number. has_number = False starts with the assumption "no digits yet." Then for char in password: walks through the password one character at a time, and if char.isdigit(): flips has_number to True the moment it finds one.

At the end, the verdict: if the password had a number, it's "Strong"; if it got this far without one, it's "Medium".

Flowchart of check_password: a length gate returning Weak, then a loop that scans for a digit, then a flag check returning Strong or falling through to Medium

Short password β†’ Weak. Long with a number β†’ Strong. Long without β†’ Medium. That's the whole idea.

TRACE IT πŸ”

Reading a function top to bottom is one thing. Watching a single password fall through it is another. Here's "Sunrise7", step by step:

Now the same function, three different passwords:

Trace table showing cat returns Weak, raspberry returns Medium, and Sunrise7 returns Strong, with the length and digit checks for each

Notice "Sunrise7" in that last row. It's exactly 8 characters, and 8 < 8 is False - so it clears the gate by one character. That's the difference between < and <=, and it's the kind of detail that decides whether real code works.

COMMON BUG πŸ›

The single most common beginner slip in a function like this is forgetting the word return:

def check_password(password):
    if len(password) < 8:
        "Weak"

That line makes the string "Weak" and then throws it away. A Python function that never hits a return hands back None - so your caller gets nothing, silently. If your function seems to "do nothing," check your returns first.

WHY IT MATTERS 🧠

This tiny function is the shape of almost all validation code: guard, gather, decide. Guard against the obvious failure and bail early. Gather information by walking the data. Decide at the end.

You'll write that shape again for email addresses, uploaded files, form inputs, API payloads - everywhere.

WITH ADA β˜•

Reading code is good. Running it is when it clicks.

Meet Ada, your companion over at py-and-jam.com. Paste this function in and she'll run it for you - no setup, no installing anything - so you can watch it actually work.

Try it on three passwords: something short, your real one, and something long with a number in it. Watch the verdict change.

LEVEL UP πŸš€ Once it runs, try making the length a setting instead of a hard-coded 8:

def check_password(password, min_length=8):
    if len(password) < min_length:
        return "Weak"

Now check_password("cat") still works, and check_password("cat", 2) gets a different answer.

ANSWER KEY βœ…

Blanked today: none - Day 1 is always the full function.

def check_password(password):
    if len(password) < 8:
        return "Weak"
    has_number = False
    for char in password:
        if char.isdigit():
            has_number = True
    if has_number:
        return "Strong"
    return "Medium"

See you tomorrow - the first lines start disappearing. 🐍 The Py & Jam Team

There's a better way to learn.

Py & Jam delivers one memorable disappearing function to your inbox daily. It’s a simple, effective way to build fluency without the frustration.