Logo
READLEARNKNOWCONNECT
Back to Lessons

    Page

  • - Numbers in Python
  • - Basic Arithmetic Operators
  • - Arithmetic in Action
  • - Order of Operations
  • - Working with Floats
  • - Useful Math Functions
  • - Using the math module
  • - Mini Project Step

6. Numbers and Basic Operations

Level: BeginnerDuration: 26m

Numbers in Python

Python works with different types of numbers. The most common ones are integers and floats.

TypeDescriptionExample
intWhole numbers5, 100, -42
floatDecimal numbers3.14, -0.7, 2.0

Basic Arithmetic Operators

Python can perform basic math easily using operators.

OperatorMeaningExample
+Addition5 + 3 → 8
-Subtraction10 - 4 → 6
*Multiplication6 * 7 → 42
/Division (float result)15 / 2 → 7.5
//Floor Division15 // 2 → 7
%Modulus (remainder)10 % 3 → 1
**Exponent3 ** 2 → 9

Arithmetic in Action

python
x = 10
y = 3
print(x + y)   # 13
print(x / y)   # 3.333...
print(x // y)  # 3
print(x ** y)  # 1000

Order of Operations

Python follows the standard math order: Parentheses → Exponents → Multiplication/Division → Addition/Subtraction (PEMDAS).

python
result = 2 + 3 * 4
print(result)       # 14
result = (2 + 3) * 4
print(result)       # 20

Working with Floats

Floating-point numbers may not always be exact due to precision limits.

python
print(0.1 + 0.2)  # 0.30000000000000004
💡 This is normal in programming—computers store decimals in binary, which can cause tiny rounding errors.

Useful Math Functions

Python includes basic math utilities without any import.

FunctionDescriptionExample
round()Round numberround(3.8) → 4
abs()Absolute valueabs(-7) → 7
pow()Power functionpow(2,3) → 8
max()Largest valuemax(3,8,2) → 8
min()Smallest valuemin(3,8,2) → 2

Using the math module

python
import math
print(math.sqrt(16))     # 4.0
print(math.pi)           # 3.141592653589793

Mini Project Step

In your bank_account.py file, add simple deposit and withdrawal calculations using + and -. Also display account balance using formatted output like: print(f"Your balance is {balance} Naira").