Back

Activity 1.4: Arithmetic Operations

divider

Activity 1.4

Arithmetic Operations

Key Concepts

Doing Math in Python

Operators, Expressions, and Order of Operations

Basic Operators

  • + Addition
  • - Subtraction
  • * Multiplication
  • / Division

Basic Operators

Demo
a = 10
b = 3
print(a + b)
print(a - b)
print(a * b)
print(a / b)
Demo
13
7
30
3.3333333333333335

More Operators

  • // Floor Division (drops the decimal)
  • % Modulus (the remainder)
  • ** Exponent (raises to a power)

More Operators

Demo
a = 10
b = 3
print(a // b)
print(a % b)
print(a ** b)
Demo
3
1
1000

Order of Operations

Python follows the same order of operations you use in math class. Use parentheses () to control what happens first.

Order of Operations

Demo
print(4 * 10 + 12)
print(4 * (10 + 12))
Demo
52
88

Today's Objectives

  • Performing arithmetic on variables
  • Using floor division, modulus, and exponents
  • Controlling order of operations with parentheses

Key Terms

Operator
A symbol that performs an operation, such as + or *.
Operand
A value an operator works on.
Expression
A combination of values and operators that produces a result.
Floor Division
Division that drops any decimal remainder, using //.
Modulus
The remainder left over after division, using %.
Order of Operations
The rules that decide which part of an expression is evaluated first.

'F' → Fullscreen

divider

Build

Create a new Python program named 1-4-arithmetic.


Task 1: Basic Operators

  • Create two number variables, side1 and side2.
  • Print the sum, difference, product, and quotient of the two variables, each with a label.
Arithmetic Operations
side1 = 8
side2 = 5
print("Sum:", side1 + side2)
print("Difference:", side1 - side2)
print("Product:", side1 * side2)
print("Quotient:", side1 / side2)
#

Task 2: Floor Division and Modulus

  • Print the floor division (//) and modulus (%) of your two variables, each with a label.
Arithmetic Operations
side1 = 8
side2 = 5
print("Sum:", side1 + side2)
print("Difference:", side1 - side2)
print("Product:", side1 * side2)
print("Quotient:", side1 / side2)
print("Floor Division:", side1 // side2)
print("Modulus:", side1 % side2)
#

Task 3: Exponents

  • Print your first variable raised to the power of your second variable (**), with a label.
Arithmetic Operations
side1 = 8
side2 = 5
print("Sum:", side1 + side2)
print("Difference:", side1 - side2)
print("Product:", side1 * side2)
print("Quotient:", side1 / side2)
print("Floor Division:", side1 // side2)
print("Modulus:", side1 % side2)
print("Exponent:", side1 ** side2)
#

Challenge (Optional): Order of Operations

  • Print the result of an expression that combines addition and multiplication two different ways — once without parentheses, and once with parentheses placed so the result changes.
divider

Checkpoint

Verify your program works correctly.

Example Output
Sum: 13
Difference: 3
Product: 40
Quotient: 1.6
Floor Division: 1
Modulus: 3
Exponent: 32768
divider

Reflection

Answer the following questions before submitting your work.

  1. What is the difference between / and // in Python?
  2. Why did adding parentheses change the result in the Challenge task?
  3. Which operator was the least familiar to you before this activity?
divider

Submit

Submit the required files to the appropriate dropbox.

Activity Complete