Computer Science
Grade 6
20 min
Basic Formulas: Performing Calculations
Students will learn to use basic formulas (e.g., SUM, AVERAGE, COUNT) to perform calculations on data.
Tutorial Preview
1
Introduction & Learning Objectives
Learning Objectives
Translate a real-world math problem into a computer formula using variables.
Correctly use the arithmetic operators (+, -, *, /) in code to perform calculations.
Explain and apply the order of operations (PEMDAS/BODMAS) in a programming context.
Use parentheses to control the order of calculations in a formula.
Store the result of a calculation in a new variable.
Debug simple calculation errors in a line of code.
Ever wonder how a video game instantly calculates your final score with all the bonuses? 🎮 Let's learn how to teach a computer to be a math whiz!
In this lesson, you'll discover how to write basic formulas in code. We'll learn how computers use variables and math symbols, called operators, to solve problems, from calculating game...
2
Key Concepts & Vocabulary
TermDefinitionExample
FormulaA set of instructions, like a recipe, that tells the computer how to perform a calculation using variables and numbers.In code, a formula to find the area of a rectangle might look like: `area = length * width`
OperatorA symbol that tells the computer to perform a specific mathematical or logical action.The plus sign `+` is an operator that tells the computer to add two numbers. Others include `-` (subtract), `*` (multiply), and `/` (divide).
ExpressionA combination of values, variables, and operators that a computer can evaluate to produce a single result.`5 + 10` is an expression. `player_score * 2` is also an expression.
AssignmentThe act of storing a value or the result of a calculation in a variable. We use the equals sign `=` for assignment.`final_score...
3
Core Syntax & Patterns
Arithmetic Operators
`+` (Addition), `-` (Subtraction), `*` (Multiplication), `/` (Division)
These are the basic symbols used to perform math in code. They are placed between two numbers or variables to calculate a result.
The Assignment Pattern
`variable_name = expression`
This is the fundamental pattern for calculations. The computer first solves the entire expression on the right side of the equals sign, and then stores the final answer in the variable on the left.
Order of Operations (PEMDAS)
1. Parentheses `( )` 2. Exponents (we'll skip for now) 3. Multiplication `*` and Division `/` (from left to right) 4. Addition `+` and Subtraction `-` (from left to right)
Computers follow this strict order to avoid confusion. Use parentheses `( )` to force a part of...
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
You buy 3 notebooks that cost $4 each and a pen that costs $2. You have a $1 discount coupon. Which formula correctly calculates the `final_cost`?
A.final_cost = 3 * 4 + 2 - 1
B.final_cost = 3 + 4 + 2 - 1
C.final_cost = (3 * 4) - 2 + 1
D.final_cost = 3 * (4 + 2) - 1
Challenging
To find the average of three scores (90, 80, 70), a student needs to add them together and then divide by 3. Which line of code does this correctly?
A.average = 90 + 80 + 70 / 3
B.average = (90 + 80 + 70) / 3
C.average = 90 + (80 + 70) / 3
D.average = 90 / 3 + 80 / 3 + 70
Challenging
A group of 4 friends buys a video game for $40 and 2 snacks for $5 each. They want to split the cost evenly. A student writes this code: `cost_per_person = 40 + 2 * 5 / 4`. What is the logical error in this formula?
A.It should be `40 * 2 + 5 / 4`.
B.It calculates the cost of snacks per person first, then adds the full game price.
C.It adds the game price and snacks first, but then divides only the snack cost by 4.
D.The variable name is invalid.
Want to practice and check your answers?
Sign up to access all questions with instant feedback, explanations, and progress tracking.
Start Practicing Free