0
0
Pythonprogramming~15 mins

Iteration using range() in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Iteration using range()
📖 Scenario: You are helping a small bakery count the number of cupcakes they have baked each day for a week. They want to print the day numbers from 1 to 7 to keep track.
🎯 Goal: Build a simple program that uses range() to iterate through the days of the week (1 to 7) and print each day number.
📋 What You'll Learn
Create a variable to hold the total number of days (7)
Use range() to generate numbers from 1 to 7
Use a for loop with variable day to iterate over the range
Print each day number inside the loop
💡 Why This Matters
🌍 Real World
Counting days or items is common in many jobs, like tracking sales, attendance, or production.
💼 Career
Understanding how to use <code>range()</code> and loops helps automate repetitive tasks and process lists of data efficiently.
Progress0 / 4 steps
1
Set the total number of days
Create a variable called total_days and set it to 7.
Python
Need a hint?

Use the equals sign = to assign the number 7 to total_days.

2
Create a range of days
Create a variable called days and set it to range(1, total_days + 1) to generate numbers from 1 to 7.
Python
Need a hint?

Remember that range() stops before the last number, so add 1 to total_days.

3
Use a for loop to iterate over days
Use a for loop with variable day to iterate over days.
Python
Need a hint?

Write for day in days: and indent the next lines inside the loop.

4
Print each day number
Inside the for loop, write print(day) to display each day number.
Python
Need a hint?

Use print(day) inside the loop to show each day number on its own line.