Created
December 6, 2017 08:31
-
-
Save spaghettiSyntax/709b3a194ed2113a77a97855a3a3cb35 to your computer and use it in GitHub Desktop.
Tony Gaddis Python: Fractions
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
# Anthony McCann | |
# 11/13/17 | |
# CPW 101 Programming Assignment 6 | |
# The primary purpose of this assignment is to apply a for loop, a range, | |
# and a variable to generate a sequence of values. The secondary purpose | |
# of this assignment is to use a running total. | |
user_value = int(input('Input a positive integer: ')) | |
# Add 1 to user value for proper range | |
n = user_value + 1 | |
# Set accumulators | |
total_1 = 0.0 | |
total_2 = 0.0 | |
for i in range(1, n): | |
total_1 += 1 / i | |
total_2 += (n - i) / i | |
print('For n =', user_value, 'the sum 1/1 + 1/2 + ... + 1/n is', total_1) | |
print('For n =', user_value, 'the sum n/1 + (n-1)/2 + ... + 1/n is', total_2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment