EX | Exercise For |
Introduction
This unit includes loop-based challenges with logic, pattern recognition, and list updates.
Task 1: FizzBuzz Variation
Instructions:
- Write a loop that goes from 1 to 40.
- If a number is divisible by 4, print “Four”.
- If a number is divisible by 6, print “Six”.
- If divisible by both, print “FourSix”.
- Else, print the number.
Task 2: Shorten Names
Instructions:
- Define a list:
names = ["Alexander", "Beatrice", "Charlotte", "Daniel", "Ella"]
- Use a
for
loop to print each name - Use a
for
loop to print only the first 3 letters of each name.
Task 3: Create a Filtered List
Instructions:
- Create an empty list called
short_names
short_names = []
- Loop through the
names
list. - If the name has fewer than 7 letters, add it to
short_names
. - Print the result list.