EX Exercise For

Introduction

This unit includes loop-based challenges with logic, pattern recognition, and list updates.

Task 1: FizzBuzz Variation

Instructions:

  1. Write a loop that goes from 1 to 40.
  2. If a number is divisible by 4, print “Four”.
  3. If a number is divisible by 6, print “Six”.
  4. If divisible by both, print “FourSix”.
  5. Else, print the number.

Task 2: Shorten Names

Instructions:

  1. Define a list: names = ["Alexander", "Beatrice", "Charlotte", "Daniel", "Ella"]
  2. Use a for loop to print each name
  3. Use a for loop to print only the first 3 letters of each name.

Task 3: Create a Filtered List

Instructions:

  1. Create an empty list called short_names
    short_names = []
    
  2. Loop through the names list.
  3. If the name has fewer than 7 letters, add it to short_names.
  4. Print the result list.

Updated: