Question: Python HW 1.Write a program that approximates the sum of this geometric series using a user- specified number of terms. For example, if you named

Python HW

1.Write a program that approximates the sum of this geometric series using a user- specified number of terms. For example, if you named your program approx, calling approx(3) should use the first 3 terms of the series to calculate the approximation:

Approximate result = 1/2 + 1/4 + 1/8 = 0.875... Note: the values are all powers of 12: (1/2)1, (1/2)2, (1/2)3, ...

Next, have your program calculate the difference (rounded to 3 decimal places) between the value 1 and the approximation calculated by your program:

Difference = 1 approximate result = 0.125

HINT: You will probably want to define some variables before your for loop, such as a variable to keep track of the value of the current term and a variable to keep track of the sign of the current term. For example, initially, you can have approx = 0. As the program iterates through the loop, approx can be modified using approx = approx + current.

(NOTE: Make sure your program is not doing integer division (see p. 59). If you are using a version of Python earlier than Python 3, the division operator / may not give you the result you are expecting.)

2.You may have noticed that the approximation, at least using just 3 terms, is not very accurate. Modify your program from part a to look at all how the approximation improves as more terms are used. Your modified program will NOT do the comparison to 1 it will just print out the value of the current approximation. For example, if you name your modified program approx2, calling approx2(3) will print out the following:

0.5 0.75 0.875

3.Now have your modified program round responses to 2 decimal places. How many terms are needed for the approximation to return a result of 0.99 or greater?

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!