Add Chapter 6 python files and fix grammar issues in readme
This commit is contained in:
parent
a84f1223bf
commit
bcb2885eeb
15 changed files with 422 additions and 3 deletions
18
thinkcspy/Chapter-6-Exercises/Python-files/problem15.py
Normal file
18
thinkcspy/Chapter-6-Exercises/Python-files/problem15.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Runestone.Academy thinkcspy course
|
||||
# Chapter 6
|
||||
# Problem 15
|
||||
|
||||
def myPi(iters):
|
||||
# Calculate an approximation of PI using the Leibniz
|
||||
# approximation with iters number of iterations
|
||||
|
||||
# your code here
|
||||
apprPi = 0
|
||||
|
||||
for i in range(iters):
|
||||
term = (-1)**i/(2*i+1)
|
||||
apprPi += term
|
||||
|
||||
return apprPi * 4
|
||||
|
||||
print(myPi(1000000))
|
||||
Loading…
Reference in a new issue