๐ฏ Learning Objectives
By the end of this lesson, learners will be able to:
-
Understand and use Python’s arithmetic operators
-
Write mathematical expressions in Python
-
Apply operator precedence rules
-
Perform integer, float, and modular arithmetic
๐ Lesson Content
๐น What Are Arithmetic Operators?
Arithmetic operators are used to perform basic mathematical operations in Python.
Operator | Description | Example (a = 10 , b = 3 ) |
Result |
---|---|---|---|
+ |
Addition | a + b |
13 |
- |
Subtraction | a - b |
7 |
* |
Multiplication | a * b |
30 |
/ |
Division (float) | a / b |
3.33 |
// |
Floor Division | a // b |
3 |
% |
Modulus (Remainder) | a % b |
1 |
** |
Exponentiation | a ** b |
1000 |
๐ธ Examples
โ ๏ธ Division Notes
-
/
always returns a float -
//
discards the decimal part (floor value)
๐ Operator Precedence (BODMAS/PEMDAS)
Python follows this order:
-
()
Parentheses -
**
Exponentiation -
* / // %
Multiplication, Division, Floor, Modulus -
+ -
Addition, Subtraction
๐ Expression Example:
โ
Always use parentheses ()
to control the order clearly.
๐ง Mini Exercise
Write a Python program to:
-
Add two numbers
-
Subtract one from the other
-
Multiply them
-
Divide them and print both
/
and//
result
๐ Assignment
Ask the user for two numbers using input()
and display:
-
Their sum
-
Their difference
-
Their product
-
Their quotient
-
Their remainder
๐ก Use int()
or float()
to convert user inputs.