Activity 03 - Lesson: Loop Structures in Python
"for" Loop Exercises
Exercise 1: Make a list of your favorite subjects in school. Use a for loop to print each
subject on a new line.
subjects = ["Math", "Science", "History", "English"]
for subject in subjects:
print(subject)
Exercise 2: Use a for loop and range() to print the numbers from 5 to 15.
for number in range(5, 16):
print(number)
Exercise 3: Ask the user to enter their name. Then, use a for loop to print "Hello" and their
name 3 times.
name = input("Enter your name: ")
for i in range(3):
print("Hello", name)
"while" Loop Exercises
Exercise 1: Write a while loop that prints the numbers from 1 to 10.
number = 1
while number <= 10:
print(number)
number = number + 1
Exercise 2: Write a while loop that asks the user to guess a secret number (you can choose
the number). The loop should keep asking until the user guesses correctly. (For an extra
challenge, give them a hint like "Too high" or "Too low".)
secret_number = 7
guess = int(input("Guess the secret number (between 1 and 10): "))
while guess != secret_number:
if guess < secret_number:
print("Too low!")
else:
print("Too high!")
guess = int(input("Guess again: "))
print("You guessed it!")
Exercise 3: Write a while loop that simulates a simple countdown timer. The user enters a
starting number, and the loop counts down to 0.
start_number = int(input("Enter a starting number: "))
while start_number >= 0:
print(start_number)
start_number = start_number - 1
print("Blast off!")