Common Number Mistakes
The problem...
Numbers seem straightforward. You add, subtract, multiply, divide.
But Python has quirks. And some of them will catch you off guard.
These are the mistakes almost every beginner makes with numbers. At least once.
Mistake 1 — Division always returns float
result = 10 / 2
print(result) # 5.0 — not 5
print(type(result)) # <class 'float'>
Even when the result is whole, / returns a float. Use // if you need an int.
Mistake 2 — int() truncates, it doesn't round
print(int(3.9)) # 3 — not 4
print(int(-3.9)) # -3 — not -4
int() cuts off the decimal. Always. Use round() if you want rounding.
Mistake 3 — Float precision
print(0.1 + 0.2) # 0.30000000000000004
print(0.1 + 0.2 == 0.3) # False
Floats are stored in binary and can't always represent decimals exactly. This is not a Python bug — it's how floating point works everywhere.
Mistake 4 — Mixing types unexpectedly
age = "25"
print(age + 5) # TypeError — can't add str and int
If it came from input(), it's a string. Always convert before doing math.
age = int(input("Enter your age: "))
print(age + 5) # works
Mistake 5 — Dividing by zero
print(10 / 0) # ZeroDivisionError
Python throws an error immediately. Always make sure your divisor isn't zero.
Mistake 6 — Forgetting operator precedence
print(2 + 3 * 4) # 14 — not 20
print((2 + 3) * 4) # 20
Python follows standard math order — multiplication before addition. Use parentheses when in doubt.
Mistake 7 — banker's rounding
print(round(0.5)) # 0 — not 1
print(round(1.5)) # 2
print(round(2.5)) # 2 — not 3
Python uses banker's rounding — rounds to the nearest even number when exactly halfway. It's by design, not a bug.
What's really happening
Most of these mistakes come from assumptions.
You assume division gives an int. You assume round() always rounds up. You assume 0.1 + 0.2 is 0.3.
Python is precise. Your assumptions aren't always.
The mindset shift
Stop thinking: "This should work."
Start thinking: "What is Python actually doing here?"
What you should understand now
- Division always returns float — use
//for int int()truncates — useround()for rounding- Float precision is a known quirk — not a bug
- Input always returns string — convert before math
- Division by zero crashes — always
- Operator precedence applies — use parentheses