# version 1 of the Leibniz sum for pi (Exercise 2.17)
# int -> number
def leibniz(terms):
"""Returns the sum of the first terms of Leibniz's series for pi."""
acc = 0
num = 4
den = 1
multiplier = 1
for aterm in range(terms):
nextterm = num/den * multiplier
acc = acc + nextterm
den = den + 2
multiplier = multiplier * -1
return acc