Member-only story

9 Scenarios Where Traditional Math Fails in Python

Python Coding
2 min readSep 20, 2024

--

1. Floating-Point Precision Errors:

print(0.1 + 0.2)
0.30000000000000004

2. Division by Zero:

print(1 / 0)
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
Cell In[1], line 1
----> 1 print(1 / 0)

ZeroDivisionError: division by zero

3. Negative Numbers in math.sqrt():

import math
print(math.sqrt(-1))
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[4], line 2
1 import math
----> 2 print(math.sqrt(-1))

ValueError: math domain error

4. Modulo of Negative Numbers:

print(-10 % 3)
2

--

--

Python Coding
Python Coding

Written by Python Coding

Learn python tips and tricks with code I Share your knowledge with us to help society. Python Quiz: https://www.clcoding.com/p/quiz-questions.html

No responses yet