Morning! π βοΈ
Almost the whole body is gone today.
The length check, the loop, and now the has_number decision - all blank. What's left on the page is close to bare bones: the def line, the loop header, the flag, and the two final verdicts.
Don't panic at the blanks. Take a breath and go one piece at a time - short-check, loop, decision. Picture yesterday's answer key and let the lines come back on their own. If you can rebuild it today, tomorrow's blank page will feel easy.
In today's email...
-
π Day 4: Most of the body is blank - only the frame remains
-
π The line that turns "did we find a number?" into a verdict
-
β Ada hands you a password to test your version on
THE FUNCTION π
def check_password(password):
____________________
____________________
has_number = False
for char in password:
____________________
____________________
____________________
return "Strong"
return "Medium"
TODAY'S LINE π
The new blank is the decision line:
if has_number:
By the time the loop finishes, has_number is either True (we found a digit) or still False (we didn't). This one line reads that flag and picks the ending.
if has_number: is Python shorthand for if has_number == True: - when the flag is True, the indented return "Strong" runs. If it's False, that branch is skipped and the function falls through to the last line, return "Medium".
See how the whole function funnels down to here? Line 4 (has_number = False, still visible) sets the flag, the loop maybe flips it, and this line reads it. Set a flag, change it while you work, check it at the end - that trio is one of the most useful habits in programming, and you just built all three.
WITH ADA β
Rebuild the body from memory, then bring it to Ada at py-and-jam.com.
Ada will hand you a password to try - something like "Sunrise7". Run your function on it and check: does your verdict match what you'd expect? If a line is off, Ada shows you exactly where, which is the fastest way to make it stick for good.
ANSWER KEY β
Today's blanked line - the has_number decision:
if has_number:
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 whole thing, from memory. π 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.