Skip to content

Commit 8e20e61

Browse files
committed
added type hints and doctests to arithmetic_analysis/newton_method.py
improved exception handling
1 parent 4ad625d commit 8e20e61

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Diff for: arithmetic_analysis/newton_method.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ def newton(function: RealFunc, derivative: RealFunc, starting_int: int,) -> floa
3333
next_guess: float = prev_guess - function(prev_guess) / derivative(
3434
prev_guess
3535
)
36-
if abs(prev_guess - next_guess) < 10 ** -5:
37-
return next_guess
38-
prev_guess = next_guess
3936
except ZeroDivisionError:
4037
raise ZeroDivisionError("Could not find root")
4138

39+
if abs(prev_guess - next_guess) < 10 ** -5:
40+
return next_guess
41+
prev_guess = next_guess
42+
4243

4344
def f(x: float) -> float:
4445
return (x ** 3) - (2 * x) - 5

0 commit comments

Comments
 (0)