Morning! π βοΈ
Yesterday you met the whole function.
Today, the first two lines are gone - the length check.
They're the easy ones. But now your brain has to reach for them instead of just reading them, and that little reach is exactly what turns "I've seen it" into "I know it."
Look at the blanks below and try to fill them in your head before you scroll.
In today's email...
-
π Day 2: First blanks - the length check disappears
-
π What those two lines actually do
-
π A short password traced through the gate
-
β Let Ada explain any line you're unsure about
THE FUNCTION π
def check_password(password):
____________________
____________________
has_number = False
for char in password:
if char.isdigit():
has_number = True
if has_number:
return "Strong"
return "Medium"
TODAY'S LINE π
The two blanked lines are the length check:
if len(password) < 8:
return "Weak"
len(password) counts how many characters the password has. < 8 asks "is that fewer than eight?" If yes, the function returns "Weak" immediately.
Notice the second line is indented further than the first. In Python, indentation is how the language knows a line belongs inside the if - the return only runs when the condition is true.
And that return does something powerful: it ends the function on the spot. A too-short password never reaches the number check at all - there's no point, it's already weak.
That's the guard clause: the very first box on the map, and the only one with its own exit door.

TRACE IT π
Watch "cat" hit the gate:
-
Line 2
len("cat")is3. Is3 < 8? Yes. -
Line 3
return "Weak". The function stops here. -
Lines 4-10 never run.
has_numberis never even created, and the loop never starts.
That last point is the whole reason the check goes first. Compare it with a password that clears the gate:

"cat" gets a verdict in two lines. "raspberry" and "Sunrise7" have to do the whole walk.
COMMON BUG π
Get the indentation wrong on these two lines and the function breaks in two very different ways.
Under-indent it and Python refuses to run at all:
if len(password) < 8:
return "Weak"
That's an IndentationError: expected an indented block. Python needs something inside the if.
Over-indent it the wrong way and it runs, but lies:
if len(password) < 8:
return "Weak"
return "Weak"
Now every password is "Weak", because that second return sits outside the if and fires for everyone. The first bug shouts. The second one is quiet - and quiet bugs are the expensive ones.
And the classic off-by-one: < 8 lets an 8-character password through. <= 8 would reject it. Yesterday's "Sunrise7" sits exactly on that line.
WHY IT MATTERS π§
"Check the deal-breaker first, then leave" is called an early return, and professional code is full of them. Every form validator, every API handler, every file uploader starts the same way: is this obviously wrong? Then stop now.
The alternative - nesting everything else inside an else: - works, but three checks deep it becomes a staircase nobody can read.
WITH ADA β
Type the two missing lines back in, then head to Ada at py-and-jam.com.
Not sure why a line works the way it does? Ask Ada to explain it. Paste the function, point at the length check, and she'll walk you through what len() and < 8 are doing - in plain English, at your pace.
Quick test: run it on "short" and then on "muchlonger". Only the second clears the length gate.
LEVEL UP π Add a second guard above the first one, for an empty password:
if not password:
return "Weak"
not "" is True, so an empty string gets caught before anything else touches it. Two guards, stacked - exactly how real validators grow.
ANSWER KEY β
Blanked today: lines 2 and 3 - the length check.
if len(password) < 8:
return "Weak"
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 loop goes next. π 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.