Lesson 5 of 12

Math in Python ➕

🎯 Grades 6–8 ⏱ ~25 minutes 💚 Intermediate

What You'll Learn

  • Use Python's arithmetic operators
  • Understand integer division and modulo
  • Build a simple calculator

Arithmetic Operators

Python
# Basic arithmetic
print(10 + 3)   # 13  (addition)
print(10 - 3)   # 7   (subtraction)
print(10 * 3)   # 30  (multiplication)
print(10 / 3)   # 3.333 (division - returns float)
print(10 // 3)  # 3   (integer division - no remainder)
print(10 % 3)   # 1   (modulo - remainder only)
print(2 ** 10)  # 1024 (exponent - 2 to the power of 10)
💪
Modulo Trick

The % operator is great for checking if a number is even or odd. If number % 2 == 0, it is even!

Order of Operations

Python follows PEMDAS (just like math class): Parentheses, Exponents, Multiply/Divide, Add/Subtract.

Python
print(2 + 3 * 4)    # 14 (not 20 - multiply first)
print((2 + 3) * 4)  # 20 (parentheses first)

Math with Variables

Python
price = 5.99
quantity = 3
total = price * quantity
tax = total * 0.085
grand_total = total + tax
print('Total:', grand_total)
🔢Simple Calculator

Build a program that:

  1. Asks for two numbers (use float())
  2. Prints their sum, difference, product, and quotient
Quick Check

What does 17 % 5 equal?

A3
B2
C4

What does 10 // 3 equal?

A3.333
B3
C0.333

Which operator means exponent (power) in Python?

A^
B**
C^^