Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
tianyizheng02 authored Dec 31, 2024
1 parent 22a3750 commit 99f8bbf
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions maths/geometric_mean.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ def compute_geometric_mean(*args: int) -> float:
"""
product = 1
for number in args:
if (not isinstance(number, int)) and (not isinstance(number, float)):
if not isinstance(number, int) and not isinstance(number, float):
raise TypeError("Not a Number")
product *= number
# Cannot calculate the even root for negative product.
# Frequently they are restricted to being positive.
if product < 0 and len(args) % 2 == 0:
raise ArithmeticError("Cannot Compute Geometric Mean for these numbers.")
mean = abs(product) ** (1.0 / len(args))
mean = abs(product) ** (1 / len(args))
# Since python calculates complex roots for negative products with odd roots.
if product < 0:
mean = -mean
Expand Down

0 comments on commit 99f8bbf

Please sign in to comment.