Skip to content

Commit

Permalink
add example typing
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael J. Wilson committed Jan 31, 2024
1 parent 556b1dd commit ac07b2f
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions python/foundation/tools.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
@profile
def calculate_pi():
def calculate_pi(n: int) -> float:
result = 0.0

# Initialize denominator
k = 1
# Initialize sum

# Initialize sum
for i in range(1_000_000):
# even index elements are positive
if i % 2 == 0:
result += 4/k
result += 4 / k
else:
# odd index elements are negative
result -= 4/k
return result
result -= 4 / k

return round(result, n)


if __name__ == "__main__":
calculate_pi()
calculate_pi(3)

0 comments on commit ac07b2f

Please sign in to comment.