Created
July 18, 2018 17:24
-
-
Save noedlm/2b140323428c4b47784c8b6ed909806a to your computer and use it in GitHub Desktop.
returns sum of a series to the nth length
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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