Question: Using Python (for or while) Calculating sum of series is an important concept. We like to write a SIMPLE program to solve the following sum.

Using Python (for or while)

Calculating sum of series is an important concept. We like to write a SIMPLE program to solve the following sum.

Using Python (for or while) Calculating sum of series is an important

Dont let the math scare you! This is just a loop that starts from 1 and goes up to n. We simply add the terms (k+1)/k. Written in the long form; it looks like:

s = 2/1 + 3/2 + 4/3 + (n+1)

as an example, when n = 5, we get s = 2/1 + 3/2 + 4/3 + 5/4 + 6/5 = 7.2833

a) Ask the user for a value for n

b) Validate the value of n to make sure its 1 or more. Give the user 3 tries to get it right. If the number is invalid after 3 tries, set s = -1

c) Display each of the values of k and k+1 as shown in the sample run.

d) Display the value of s with 4 digits after the decimal point

Sample interaction 1:

Enter a value for the final value of the series: -900

Invalid input: Enter a value for the final value of the series: 0

Invalid input: Enter a value for the final value of the series: 5

Enter a value for the final value of the series: 5 2 / 1 + 3 / 2 + 4 / 3 + 5 / 4 + 6 / 5 = 7.2833

n S K (k+ 1)/k k=1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!