Computer Science
Grade 5
20 min
Spreadsheet Project: Tracking Class Data
Students will apply their spreadsheet skills to track and analyze class data (e.g., favorite colors, birthdays).
Tutorial Preview
1
Introduction & Learning Objectives
Learning Objectives
Write a `for` loop to iterate through a list of class data, like student names or grades.
Use `if` statements to check if a student's data meets a specific condition (e.g., if a grade is passing).
Construct an `if-elif-else` chain to sort data into multiple categories (e.g., letter grades A, B, C).
Combine loops and conditionals to analyze an entire list of data.
Use a counter variable inside a loop to count how many items in a list meet a certain criteria.
Explain the difference between the assignment operator (`=`) and the equality operator (`==`).
Ever wonder how your teacher can instantly find out who has perfect attendance or who made the honor roll? 🧑🏫 Let's learn the secret code that makes it happen!
In this lesson, we'll learn a...
2
Key Concepts & Vocabulary
TermDefinitionExample
Control StructureA block of code that decides the order in which other code runs. It controls the 'flow' of the program, like a traffic light controls the flow of cars.An `if` statement is a control structure because it decides *if* a certain piece of code should run.
ConditionalA statement that runs code only if a certain condition is true. We use `if`, `elif` (else if), and `else` for this.`if score > 90: print('Excellent!')` This code only prints 'Excellent!' if the value in the `score` variable is greater than 90.
LoopA structure that repeats a block of code over and over. A `for` loop repeats the code for each item in a list.`for student in names: print('Hello, ' + student)` This will greet every single student in the `...
3
Core Syntax & Patterns
The `if-elif-else` Structure
if condition1:
# code to run if condition1 is True
elif condition2:
# code to run if condition1 is False and condition2 is True
else:
# code to run if all above conditions are False
Use this to check a series of conditions. Python checks them in order and only runs the code for the *first* one that is True. The `else` block is a catch-all for when nothing else matches.
The `for` Loop Structure
for variable_name in list_name:
# code to run for each item
# use variable_name to access the current item
Use this to perform an action on every single item in a list. The `variable_name` is a temporary variable that holds one item from the list at a time, for each iteration of the loop.
The Counter Pattern
counter = 0
for item in...
4 more steps in this tutorial
Sign up free to access the complete tutorial with worked examples and practice.
Sign Up Free to ContinueSample Practice Questions
Challenging
Your task is to find the average project score, but ONLY for students who are in the 'Robotics Club'. Which of these is the best plan for your code?
A.Loop through all students. Inside the loop, use an `if` to check if they are in Robotics Club. If they are, add their score to a total and add 1 to a counter. After the loop, divide the total by the counter.
B.First, calculate the average score of all students. Then, find out how many are in the Robotics club and multiply.
C.Create two separate lists, one for scores and one for clubs. Loop through both at the same time and find the average.
D.Loop through all students and add up all project scores. Then, loop through all students again to count how many are in the Robotics Club. Divide the total score by the club count.
Challenging
A program tries to find students whose score on `test2` was higher than on `test1`. The code is: `for student in class_data: if student['test2'] > student['test1']: print(student['name'])`. What is a potential problem with this code if some students were absent for `test2`?
A.The `>` operator does not work on test scores.
B.The `for` loop will skip absent students.
C.The code might crash if an absent student has no score for `test2`.
D.The code will incorrectly think a low score is an improvement.
Challenging
In our class data, each student has a unique binary ID. A teacher wants to split the class into two groups for a project. They use the code `if student_id & 1:`. What is this code checking?
A.If the student ID is the number 1.
B.If the student ID is greater than 1.
C.If the student ID is an even number.
D.If the student ID is an odd number.
Want to practice and check your answers?
Sign up to access all questions with instant feedback, explanations, and progress tracking.
Start Practicing Free