Question

4. Pi is an irrational number whose first digits are: 3.1415928. The precise value of pi is equal to the infinite sum: pi = 4/1-4/3 + 4/5-4/7 + 4/9-4/11 + You can compute better and better approximations of pi by computing more terms of the series. Write function approxPi(deltaValue) that computes and returns an approximation of pi. Use a while loop (not a for loop) Each iteration should update the pi approximation by including one additional term from the series. The loop should terminate when the difference between the previous iterations approximation and the new iterations approximation is less than deltaValue. For example approxPL(.01) 3.1465677471829556 >>>approxPi(-00S) 3.144086415298了61 approxPi 00001) 3.141597653564762

Note: you may not use list comprehensions or similar Python constructs not taught yet in this course. Use while loops (or for loops, except while required in Q4) for iteration. You may not use any string methods other than .lower()

this is a python work, i don't know how to do this, i need you help, thanks you very much!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

get "val" as argument.

count = 1.0
pi=4.0
old=0.0
while ((pi-old>=val and pi-old>0) or (old-pi>=val and old-pi>0)):     
old=pi
count+=2
pi=pi-(4.0/count)
if(pi-old>=val and pi-old>0) or (old-pi>=val and old-pi>0):
old=pi
count+=2
pi=pi+(4.0/count)
  
print(pi);

Add a comment
Know the answer?
Add Answer to:
Note: you may not use list comprehensions or similar Python constructs not taught yet in this...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • clearvars close all clc tol = 0.0001; % this is the tolerance for root identification xold...

    clearvars close all clc tol = 0.0001; % this is the tolerance for root identification xold = 0.5; % this is the initial guess test = 1; % this simply ensures we have a test value to enter the loop below. %If we don't preallocate this, MATLAB will error when it trys to start the %while loop below k = 1; %this is the iteration counter. Similar to "test" we need to preallocate it %to allow the while loop to...

  • PLEASE USE WHILE LOOP (NOT FOR LOOPS). Python programming. In this problem, you should write one...

    PLEASE USE WHILE LOOP (NOT FOR LOOPS). Python programming. In this problem, you should write one function named multiply. This function should accept one parameter, which you can assume will be a list with one or more integers in it. (If you don’t know what I mean when I say “list of integers”, go do the reading!) The function should loop through all of the numbers in the list, and multiply all of the numbers together. It should return the...

  • Python pleases! Write a program that will produce the following table below. You will use a...

    Python pleases! Write a program that will produce the following table below. You will use a nested for loop and a duplicate nested while loop in one program. Note that this is the one through twelve multiplication table. Write the flowchart for the program. X 1 2 3 4 5 6 7 8 9 10 11 12 1 1 2 3 4 5 6 7 8 9 10 11 12 2 2 4 6 8 10 12 14 16 18...

  • Newton's Method in MATLAB During this module, we are going to use Newton's method to compute...

    Newton's Method in MATLAB During this module, we are going to use Newton's method to compute the root(s) of the function f(x) = x° + 3x² – 2x – 4 Since we need an initial approximation ('guess') of each root to use in Newton's method, let's plot the function f(x) to see many roots there are, and approximately where they lie. Exercise 1 Use MATLAB to create a plot of the function f(x) that clearly shows the locations of its...

  • Could someone please help me write this in Python? If time allows, it you could include...

    Could someone please help me write this in Python? If time allows, it you could include comments for your logic that would be of great help. This problem involves writing a program to analyze historical win-loss data for a single season of Division I NCAA women's basketball teams and compute from this the win ratio for each team as well as the conference(s) with the highest average win ratio. Background Whether it's football, basketball, lacrosse, or any other number of...

  • python program do not use dictionary, list only Complete the program found in assignment4.py. You may...

    python program do not use dictionary, list only Complete the program found in assignment4.py. You may not change any provided code. You may only complete the sections labeled: #YOUR CODE HERE Write a program that does the following. Reads the contents of Text from the include file, input.txt Create a dictionary of key-value pairs called index.txt Key: This represents the individual word Value: This is a list of the line number from Text where Key appeared Example: If the word...

  • You need not run Python programs on a computer in solving the following problems. Place your...

    You need not run Python programs on a computer in solving the following problems. Place your answers into separate "text" files using the names indicated on each problem. Please create your text files using the same text editor that you use for your .py files. Answer submitted in another file format such as .doc, .pages, .rtf, or.pdf will lose least one point per problem! [1] 3 points Use file math.txt What is the precise output from the following code? bar...

  • please use python and provide run result, thank you! click on pic to make it bigger...

    please use python and provide run result, thank you! click on pic to make it bigger For this assignment you will have to investigate the use of the Python random library's random generator function, random.randrange(stop), randrange produces a random integer in the range of 0 to stop-1. You will need to import random at the top of your program. You can find this in the text or using the online resources given in the lectures A Slot Machine Simulation Understand...

  • Pseudocode & Python In this portion of the project you will analyze a problem and create...

    Pseudocode & Python In this portion of the project you will analyze a problem and create a Python program to solve it. In recent years, there has been more attention to Water Quality. Specifically the amount of lead that is found in our daily water supply. Lead and copper residue start to show up in our water supply due to aging pipes. This residue can be found in older homes that have not replaced their pipes and in the municipal...

  • Use C++ For this week’s lab you will write a program to read a data file...

    Use C++ For this week’s lab you will write a program to read a data file containing numerical values, one per line. The program should compute average of the numbers and also find the smallest and the largest value in the file. You may assume that the data file will have EXACTLY 100 integer values in it. Process all the values out of the data file. Show the average, smallest, largest, and the name of the data file in the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT