Computer Science Grade 9 20 min

Balancing Screen Time

Balancing Screen Time

Tutorial Preview

1

Introduction & Learning Objectives

Learning Objectives Define key terms related to digital wellness and data analysis. Represent screen time activities using a list of dictionaries in a program. Write a simple algorithm using a loop to calculate total screen time from a given dataset. Apply conditional logic (if/else statements) to categorize screen time as 'productive' or 'leisure'. Analyze the output of a program to make informed decisions about their digital habits. Design a simple function that suggests taking a break based on a time-based input parameter. Ever wonder where all your time goes on your phone? 📱 Let's use the power of programming to find out and take control! This lesson explores how we can apply fundamental computer science concepts to understand and manage our di...
2

Key Concepts & Vocabulary

TermDefinitionExample Screen Time DataQuantitative information representing the time spent on digital devices, often broken down by application or category.A log file showing: YouTube - 120 minutes, Google Docs - 45 minutes, Instagram - 90 minutes. Data StructureA specialized format for organizing, processing, retrieving, and storing data. In this context, we use it to hold our screen time information in a structured way.Using a List of Dictionaries to store app usage: `[{"app": "CodeEditor", "time": 60}, {"app": "TikTok", "time": 90}]` AlgorithmA finite sequence of well-defined, computer-implementable instructions, typically to solve a class of problems or to perform a computation.A set of steps: 1. Initialize total_time to 0. 2...
3

Core Syntax & Patterns

Data Aggregation with a For Loop total = 0 for item in data_list: total = total + item['value'] Use this pattern to calculate a sum or total from a list of data. Initialize a variable to zero before the loop, then iterate through the list, adding the desired value from each element to your total. Categorization with If-Elif-Else if condition1: # do action A elif condition2: # do action B else: # do action C Use this structure to sort data into different categories. The program checks each condition sequentially and executes the code block for the first one that is true. The 'else' block catches any items that don't meet the preceding conditions.

4 more steps in this tutorial

Sign up free to access the complete tutorial with worked examples and practice.

Sign Up Free to Continue

Sample Practice Questions

Challenging
Your screen time data is a list of dictionaries, where each dictionary has keys 'day', 'app', 'category', and 'minutes'. How would you design an algorithm to find which day of the week had the highest 'Leisure' screen time?
A.Use a dictionary to store the total leisure time for each day. Loop through the data, and if an activity is 'Leisure', add its minutes to the corresponding day's total in your dictionary. Finally, find the day with the max value.
B.Create a separate list for each day of the week, then loop through the main list and append activities to the correct day's list. Then, calculate the total for each list.
C.Loop through the data once to find the total leisure time, then loop through it again to find the day with the highest total time.
D.Sort the list by minutes in descending order. The day of the first item in the sorted list is the answer.
Challenging
After calculating `total_productive_time` and `total_leisure_time` in a loop, you need to find the percentage of screen time that was productive. What are the necessary next steps?
A.Divide `total_productive_time` by `total_leisure_time` and multiply by 100.
B.Calculate `grand_total = total_productive_time + total_leisure_time`. Then, calculate `(total_productive_time / grand_total) * 100`.
C.Run the loop again, but this time divide each productive activity's minutes by 100 before adding to the total.
D.The percentage is simply `total_productive_time` because the total is always 100.
Challenging
A digital wellness app needs to alert the user if EITHER a single activity is longer than 90 minutes OR the cumulative screen time for the day exceeds 240 minutes. Which code structure inside a `for` loop best implements this?
A.`if activity['minutes'] > 90: alert(); elif total_time > 240: alert()`
B.`if activity['minutes'] > 90: alert(); if total_time > 240: alert()`
C.`if activity['minutes'] > 240 or total_time > 90: alert()`
D.`if activity['minutes'] > 90 or total_time > 240: alert()`

Want to practice and check your answers?

Sign up to access all questions with instant feedback, explanations, and progress tracking.

Start Practicing Free

More from Being a Digital Citizen

Ready to find your learning gaps?

Take a free diagnostic test and get a personalized learning plan in minutes.