Scenario: You are developing a feature for a mobile operating system that helps users track their daily screen time. The screen time for one week is recorded in a 1D array, where each element represents the number of minutes spent on an app per day.
You have been given the screen time data for a popular social media app over a period of 7 days.
Data
screen_time = [120, 85, 240, 90, 150, 60, 180]
Your tasks
Write a Python program to analyse this data. Implement the following without using built-in functions like sum(), max() or min().
- Calculate the total screen time — iterate through
screen_timeand print the total minutes for the week. - Find the maximum and minimum screen time — print both the highest and lowest single-day values.
- Count high-usage days — a high-usage day is more than two hours (more than 120 minutes). Print how many days meet this rule.
💡 Try the whole challenge in your editor first. Only reveal the solution when you have had a proper go.
Solution
screen_time = [120, 85, 240, 90, 150, 60, 180]
total = 0
highest = screen_time[0]
lowest = screen_time[0]
high_usage = 0
for minutes in screen_time:
total = total + minutes
if minutes > highest:
highest = minutes
if minutes < lowest:
lowest = minutes
if minutes > 120:
high_usage = high_usage + 1
print("Total screen time for the week:", total, "minutes")
print("Highest screen time on a single day:", highest, "minutes")
print("Lowest screen time on a single day:", lowest, "minutes")
print("Number of high-usage days (more than 120 minutes):", high_usage)
Example output:
Total screen time for the week: 925 minutes
Highest screen time on a single day: 240 minutes
Lowest screen time on a single day: 60 minutes
Number of high-usage days (more than 120 minutes): 3