Scenario: You are developing a feature for a fitness smartwatch. Step counts for one week are stored in a 1D array. A second parallel array holds the weekday names so you know which day each total belongs to.
Data
weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
step_count = [8200, 11500, 4300, 12000, 9500, 3100, 10500]
Your tasks
Implement the following without sum(), max(), min() or the .index() list method.
- Calculate the weekly total steps and print the total.
- Identify peak and lowest activity days — find the highest and lowest step counts and the matching weekday from the parallel array. Print both values with their days.
- Count low-activity days — fewer than 5,000 steps. Print the count.
💡 Try the whole challenge in your editor first. Only reveal the solution when you have had a proper go.
Solution
weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
step_count = [8200, 11500, 4300, 12000, 9500, 3100, 10500]
total = 0
highest_index = 0
lowest_index = 0
low_activity = 0
for i in range(len(step_count)):
steps = step_count[i]
total = total + steps
if steps > step_count[highest_index]:
highest_index = i
if steps < step_count[lowest_index]:
lowest_index = i
if steps < 5000:
low_activity = low_activity + 1
print("Total steps taken this week:", total, "steps")
print("Highest step count:", step_count[highest_index], "steps (on", weekdays[highest_index] + ")")
print("Lowest step count:", step_count[lowest_index], "steps (on", weekdays[lowest_index] + ")")
print("Number of low-activity days (fewer than 5,000 steps):", low_activity)
Example output:
Total steps taken this week: 59100 steps
Highest step count: 12000 steps (on Thursday)
Lowest step count: 3100 steps (on Saturday)
Number of low-activity days (fewer than 5,000 steps): 2