if/elif/else)This is a great pivot because it uses the random module.
if/elif/else to print a different answer based on that number.if statements are just a "branching path."import random
answer = random.randint(1, 3)
if answer == 1:
print("Yes, definitely!")
elif answer == 2:
print("Ask again later...")
else:
print("My sources say no.")
This is a rite of passage for programmers. It’s simple to explain but requires them to think about how if statements work inside a loop.
The Task: Print numbers from 1 to 20. But:
If the number is divisible by 3, print "Fizz".
If it's divisible by 5, print "Buzz".
If it's divisible by both, print "FizzBuzz".
Why it works: It teaches the importance of order in if statements (checking for both 3 and 5 first).
Since you just did a password generator, let’s stay on the theme of security but simplify the code. Instead of building a password, have them check one.
for loop to look at a string character-by-character, which is a core skill you'll need.password = input("Enter a password: ")
has_special = False
for char in password:
if char == "!":
has_special = True
if has_special:
print("Strong password!")
else:
print("Weak password - add an '!'")
| Activity | Focus | Difficulty |
|---|---|---|
| Magic 8-Ball | if/elif/else |
Easy |
| FizzBuzz | for loops + Modulo (%) |
Medium |
| Security Scanner | for loops + Strings |
Medium |