Skip to content

Instantly share code, notes, and snippets.

@noedlm
Created July 18, 2018 17:24
Show Gist options
  • Save noedlm/2b140323428c4b47784c8b6ed909806a to your computer and use it in GitHub Desktop.
Save noedlm/2b140323428c4b47784c8b6ed909806a to your computer and use it in GitHub Desktop.
returns sum of a series to the nth length
from fractions import Fraction
a = float('1') / float('4')
b = '1/4'.split('/')
def series_sum(n):
if n == 0:
return "0.00"
else:
series = [Fraction(float(1) / float((3 * x) - 2)) for x in range(1, n+1)]
total = round(0, 2)
for item in series:
total += float(item)
return "{0:.2f}".format(total)
fractions = [Fraction(float(1) / float((3 * x) - 2)) for x in range(1, 10)]
series_sum(98)
# print fractions
# print "{0:.2f}".format(float(fractions[2]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment