Mathematical Expressions

David Foster
5 min read
Listen to this study note
Study Guide Overview
This study guide covers algorithms and their core components: sequencing, selection, and iteration. It explains how expressions are evaluated using arithmetic operators and the order of operations (PEMDAS/PEMMDAS). The guide also includes practice questions and exam tips focusing on algorithm identification, sequencing, and expression evaluation using the MOD operator.
AP Computer Science Principles: The Night Before ๐
Hey! Let's get you prepped and confident for tomorrow. We'll make sure everything clicks, and you'll be ready to rock this exam. Let's dive in!
Big Idea 3: Algorithms and Programming
What's an Algorithm?
An algorithm is simply a set of instructions to solve a problem or complete a task. Think of it as the logic behind a process. It's like the steps you'd take to make a cake, while the program is the recipe itself. ๐ฐ
Algorithms can be expressed in different ways: code, pseudocode, natural language, or diagrams. Computers follow your instructions exactly, so clarity is key!
Building Blocks: Sequencing, Selection, and Iteration
Every algorithm is built using three core concepts:
-
Sequencing: Steps are executed in the order they appear. It's like following a recipe from top to bottom.
first_number = 7 second_number = 5 sum_value = first_number + second_number print (sum_value)
In this example, each line is executed one after the other.
-
Selection: (We'll cover this later) This is where your code makes decisions (like if/else statements).
-
Iteration: (We'll cover this later) This is how you repeat steps (loops like
for
andwhile
).
Code statements are the individual actions in your program. They're the building blocks of algorithms.
Expressions: Getting to a Single Value
An expression is anything that returns a single value. It can be a number, a variable, or a calculation using operators.
Arithmetic Operators
Here are the operators you'll use in your code:
Operator | Description | Example |
---|---|---|
+ | Addition | 5 + 3 = 8 |
- | Subtraction | 10 - 4 = 6 |
* | Multiplication | 6 * 7 = 42 |
/ | Division | 15 / 3 = 5 |
MOD | Modulo | 13 MOD 3 = 1 |
MOD gives you the remainder after division. Think of it as the leftover bits. ๐ฐ๏ธ
Order of Operations
Expressions are evaluated using the order of operations (PEMDAS, or PEMMDAS if you include MOD). Remember:
- Parentheses
- Exponents
- Multiplication or Division (from left to right)
- MOD
- Addition or Subtraction (from left to right)
Use parentheses to make your expressions clear and avoid errors. Don't rely on PEMDAS alone!
Practice Question
{
"multiple_choice": [
{
"question": "What is the result of the expression `20 MOD 7`?",
"options": ["2", "3", "6", "20"],
"answer": "6"
},
{
"question": "Which of the following is NOT an example of an algorithm?",
"options": ["A recipe for baking a cake", "A set of instructions to assemble a desk", "A random collection of words", "A sequence of steps to solve a math problem"],
"answer": "A random collection of words"
}
],
"free_response": {
"question": "Write an algorithm in pseudocode to calculate the average of three numbers. The algorithm should:\n1. Take three numbers as input.\n2. Calculate the sum of the three numbers.\n3. Calculate the average by dividing the sum by 3.\n4. Display the average.",
"scoring_breakdown": [
"1 point for taking three numbers as input",
"1 point for calculating the sum of the three numbers",
"1 point for correctly calculating the average",
"1 point for displaying the average"
],
"sample_solution": "```\nINPUT num1\nINPUT num2\nINPUT num3\nsum = num1 + num2 + num3\naverage = sum / 3\nDISPLAY average\n```"
}
}
Final Exam Focus
- Algorithms: Understand what they are and how they're different from programs. Be able to identify algorithms in different forms (code, pseudocode, etc.).
- Sequencing: Know how code executes step-by-step.
- Expressions: Practice evaluating expressions using the correct order of operations, especially with the
MOD
operator.
Last-Minute Tips
- Time Management: Don't get stuck on one question. Move on and come back if needed.
- Common Pitfalls: Watch out for order of operations errors and be careful with the MOD operator.
- Strategies: Read questions carefully and break them down into smaller parts.
You've got this! Go get 'em! ๐ช

How are we doing?
Give us your feedback and let us know how we can improve
Question 1 of 8
What will be the output of the following code snippet? ๐ป
first_number = 10
second_number = 3
sum_value = first_number + second_number
print(sum_value)
3
10
13
7