Lesson 28 of 30
Lesson 28 ? Simple passwords
Title: Check secret words carefully
Description: Practice password checks, attempts, and clear messages.
Why it matters for kids: Login screens and secret doors use the same idea: compare what the user typed.
1. Basic password
password = input("Password: ")
if password == "cookie":
print("Welcome!")
else:
print("Wrong password.")2. Ignore uppercase mistakes
password = input("Password: ").lower()
if password == "dragon":
print("The cave opens.")
else:
print("The cave stays closed.")3. Count attempts
correct_password = "python"
attempts = 0
while attempts < 3:
password = input("Password: ")
attempts = attempts + 1
if password == correct_password:
print("Welcome!")
break
else:
print("Try again.")4. Check password length
password = input("Create password: ")
if len(password) >= 6:
print("Password is long enough.")
else:
print("Use at least 6 characters.")5. Easy examples
secret = "moon"
print(secret == "moon")word = " cat "
print(word.strip())password = "rainbow"
has_enough_letters = len(password) >= 6
print(has_enough_letters)6. Mini challenge
Click each example to open it.
Example 1
Ask for one password.
Example 2
Check if password is cookie.
Example 3
Print welcome for the right password.
Example 4
Print try again for the wrong password.
Example 5
Use lower on the password.
Example 6
Use strip on the password.
Example 7
Check if password has 5 letters.
Example 8
Check if password has 6 letters.
Example 9
Give the user three attempts.
Example 10
Make a secret cave password.