Morning! π βοΈ
Halfway through the week.
The length check is still gone from yesterday - and today the heart of the loop disappears too. About half the function is blank now.
Before you scroll, try saying the missing lines out loud. Even a whisper over your coffee counts - speaking a line is a different muscle from reading it, and it's the one that sticks.
In today's email...
-
π Day 3: The loop's inside vanishes - half the function is blank
-
π How a
forloop hunts through the password -
β Paste your version and watch Ada run it
THE FUNCTION π
def check_password(password):
____________________
____________________
has_number = False
for char in password:
____________________
____________________
if has_number:
return "Strong"
return "Medium"
TODAY'S LINE π
The two new blanks live inside the loop:
if char.isdigit():
has_number = True
The line still showing above them - for char in password: - is the loop itself. It takes the password and hands you its characters one at a time, calling each one char. First the loop sees "p", then "a", then "s", and so on to the end.
Each time through, the blanked lines ask a question: if char.isdigit(): - "is this character a digit?" The moment the answer is yes, has_number = True records it. Once it's True, it stays True, even if the rest of the characters are letters.
That's the everyday shape of a loop: set up an answer before you start (has_number = False, still visible on line 4), then walk the data and update the answer as you learn more. You now have both halves - the setup and the search.
WITH ADA β
Fill the loop back in from memory, then take the whole thing to Ada at py-and-jam.com and let her run it.
This is the real test: if your loop is right, "letters" comes back one way and "letters1" another - that single 1 is what your loop is hunting for. Watch it land.
ANSWER KEY β
Today's blanked lines - the digit check inside the loop:
if char.isdigit():
has_number = True
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 - only the verdict lines are left to fade. π 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.