TheAlgorithms/Python · error · ZeroDivisionError
Number of steps must be greater than zero
Error message
Number of steps must be greater than zero
What it means
Error "Number of steps must be greater than zero" thrown in TheAlgorithms/Python.
Source
Thrown at maths/numerical_analysis/simpson_rule.py:45
>>> round(method_2([0, 1], 10), 10)
0.3333333333
>>> round(method_2([0, 2], 10), 10)
2.6666666667
>>> round(method_2([0, 2], 100), 10)
2.5621226667
>>> round(method_2([0, 1], 1000), 10)
0.3320026653
>>> round(method_2([0, 2], 0), 10)
Traceback (most recent call last):
...
ZeroDivisionError: Number of steps must be greater than zero
>>> round(method_2([0, 2], -10), 10)
Traceback (most recent call last):
...
ZeroDivisionError: Number of steps must be greater than zero
"""
if steps <= 0:
raise ZeroDivisionError("Number of steps must be greater than zero")
h = (boundary[1] - boundary[0]) / steps
a = boundary[0]
b = boundary[1]
x_i = make_points(a, b, h)
y = 0.0
y += (h / 3.0) * f(a)
cnt = 2
for i in x_i:
y += (h / 3) * (4 - 2 * (cnt % 2)) * f(i)
cnt += 1
y += (h / 3.0) * f(b)
return y
def make_points(a, b, h):
x = a + h
while x < (b - h):View on GitHub (pinned to f5988cc097)
Solutions
- Pass an even number of steps greater than zero for Simpson's rule.
When it happens
Trigger: Thrown at maths/numerical_analysis/simpson_rule.py:45 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14).
Data as JSON: /api/errors/2a509f36306d58ce.
Report an issue: GitHub.