Python

1.Python start

1. The "Magic 8-Ball" (Mastering if/elif/else)

This is a great pivot because it uses the random module.

  • The Task: Ask the user for a question, then generate a random number between 1 and 4. Use if/elif/else to print a different answer based on that number.
  • Why it works: It reinforces that if statements are just a "branching path."
  • Code Concept:
    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.")

2. The "FizzBuzz" Challenge (Logic & Loops)

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).

3. The "Word Security" Scanner (String Iteration)

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.

  • The Task: The user inputs a password. The program loops through every character and checks if there is an "!" in it.
  • Why it works: It uses a for loop to look at a string character-by-character, which is a core skill you'll need.
  • Code Concept:
    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 '!'")

Comparison of Concepts

Activity Focus Difficulty
Magic 8-Ball if/elif/else Easy
FizzBuzz for loops + Modulo (%) Medium
Security Scanner for loops + Strings Medium