Python Basics · Lesson 4
Numbers & Arithmetic Operations
Learn how Python performs calculations using arithmetic operators, including addition, subtraction, multiplication, division, modulus, floor division and exponentiation.
What you will learn
- • Addition with +
- • Subtraction with -
- • Multiplication with *
- • Division with /
- • Remainder with %
- • Floor division with //
- • Exponents with **
- • Order of operations
Part 1
Python as a calculator
Python can perform mathematical calculations directly in your program. You can use numbers with arithmetic operators and store the results in variables.
print(10 + 5)
print(20 - 8)
print(5 * 4)
print(20 / 5)CHECK YOUR UNDERSTANDING
Which operator performs addition in Python?
Addition — +
The plus operator adds two or more numeric values.
a = 25
b = 15
total = a + b
print(total)CHECK YOUR UNDERSTANDING
What is the output of print(25 + 15)?
Complete the calculation: 50 _____ 25
Subtraction — -
The minus operator subtracts one value from another.
print(100 - 35)CHECK YOUR UNDERSTANDING
What is the output of print(100 - 35)?
Complete the calculation: 90 _____ 40
Multiplication — *
Python uses an asterisk (*) for multiplication.
price = 500
quantity = 4
total = price * quantity
print(total)CHECK YOUR UNDERSTANDING
What will print(500 * 4) display?
Complete the calculation: 12 _____ 5
Division — /
The slash operator performs division. In Python, normal division with / produces a floating-point result.
print(20 / 5)CHECK YOUR UNDERSTANDING
What is the result of 20 / 5?
CHECK YOUR UNDERSTANDING
Which operator performs normal division?
Important operator
Modulus — %
The modulus operator returns the remainder after division.
print(17 % 5)CHECK YOUR UNDERSTANDING
What is the result of 17 % 5?
CHECK YOUR UNDERSTANDING
What is the modulus operator commonly used to find?
Floor division — //
Floor division divides two numbers and returns the floor of the result.
print(17 // 5)CHECK YOUR UNDERSTANDING
What is the result of 17 // 5?
Which operator performs floor division? _____
Exponentiation — **
The ** operator raises a number to a power.
print(2 ** 3)CHECK YOUR UNDERSTANDING
What is the result of 2 ** 3?
Complete the expression for 5 squared: 5 _____ 2
Predict the output
Combine operators
result = 10 + 5 * 2
print(result)CHECK YOUR UNDERSTANDING
What will this program display?
Order of operations
Python follows the usual mathematical order of operations. Multiplication and division are performed before addition and subtraction unless parentheses change the order.
10 + 5 * 2Result: 20
(10 + 5) * 2Result: 30
CHECK YOUR UNDERSTANDING
What is the result of (10 + 5) * 2?
Arithmetic with variables
price = 250
quantity = 4
discount = 100
total = price * quantity
final_price = total - discount
print(final_price)CHECK YOUR UNDERSTANDING
What will final_price be?
Your turn
Complete the expressions
Complete the addition: 25 _____ 10
Complete the multiplication: 8 _____ 7
Complete the remainder operation: 20 _____ 6
Complete the exponent: 3 _____ 2
Debug the calculation
price = 100
quantity = 3
total = price x quantity
print(total)CHECK YOUR UNDERSTANDING
What is wrong with the multiplication expression?
Real-world practice
Calculate a shopping bill
Suppose a customer buys 3 notebooks for ₹80 each. Use variables and multiplication to calculate the total.
price = 80
quantity = 3
total = price * quantity
print(total)CHECK YOUR UNDERSTANDING
What is the total bill?
Mini Challenge
Calculate revenue
A business sells a product for ₹1,500 and sells 12 units. Create variables and calculate the total revenue.
price = 1500
units = 12
revenue = price * units
print(revenue)Expected revenue: ₹18,000
Final Challenge
Build a simple sales calculator
Create a Python program that stores product price, quantity and a discount amount. Calculate the original total and then subtract the discount to find the final price.
price = 1200
quantity = 5
discount = 500
total = price * quantity
final_price = total - discount
print(total)
print(final_price)Change the numbers and experiment with different sales scenarios.
Lesson recap
- ✓ + performs addition.
- ✓ - performs subtraction.
- ✓ * performs multiplication.
- ✓ / performs normal division.
- ✓ % returns the remainder.
- ✓ // performs floor division.
- ✓ ** performs exponentiation.
- ✓ Parentheses can change the order of operations.
- ✓ Arithmetic operators can be used with variables.