PYTHON : (ANSWER MUST BE PYTHON) You must code a program that approximates the number pi by summing a series of numbers. Mathematically the number pi is equal to the following infinite sum: pi = 4/1 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11 + ... Notice the alternation of signs from one term to another of the series (positive, negative, positive, ...) Moreover, notice that the divisors are the odd numbers. We would like to check with a program that the sum converges to pi. Here is the specification of the program: The program must sum the terms one at a time and display the sum whenever the number of terms used is a power of 10 (so at 1 term, 10 terms, 100 terms, 1000 terms, etc). On the other hand the program must stop as soon as the error (the absolute value of the difference between the sum and pi) is less than 5e-6 and indicate how many terms there are in the sum and the value of the sum. As a precaution, in case the sum does not converge fast enough, your program should stop when 10**6 terms are added and display a message indicating that the error is not less than 5e-6 after the first 10**6 terms are added. Note that the best floating point approximation of pi is found in math.pi. You must use print for all displays. You must make the display exactly in the following format: at 1 term the sum is equal to xxxxxxxxx at 10 terms the sum is equal to xxxxxxxxx at 100 terms the sum is equal to xxxxxxxxx at 1000 terms the sum is equal to xxxxxxxxx at 10000 terms the sum is equal to xxxxxxxxx the sum reaches the tolerable error of xxxxxxxxx at xxxxxxxxx terms the sum is equal to xxxxxxxxx where xxxxxxxxx is a number. If the tolerable error is not reached, then the second last line must be in this format: the sum did not reach the tolerable error from xxxxxxxxx to xxxxxxxxx terms. Your program must use significant identifiers in ASCII camelCase, it must be well indented, without too long lines, and it must be well commented. In short, as if your code will be used by another programmer in the future. Comments should include: - your name and the date at the beginning of the code - a brief explanation of the purpose of the code - an explanation of each variable declared - an explanation of how the code works (its logic) It must be easy to modify the error you are looking for. The very first statement of your program must therefore be a variable declaration. This variable must contain the floating number corresponding to the error sought by your program. When you submit, the value 5e-6 must be assigned to this variable, but it must be possible to modify it. Be sure to choose a meaningful identifier for it.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

PYTHON : (ANSWER MUST BE PYTHON)

You must code a program that approximates the number pi by summing a series of numbers. Mathematically the number pi is equal to the following infinite sum:

pi = 4/1 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11 + ...

Notice the alternation of signs from one term to another of the series (positive, negative, positive, ...) Moreover, notice that the divisors are the odd numbers.

We would like to check with a program that the sum converges to pi. Here is the specification of the program:

The program must sum the terms one at a time and display the sum whenever the number of terms used is a power of 10 (so at 1 term, 10 terms, 100 terms, 1000 terms, etc). On the other hand the program must stop as soon as the error (the absolute value of the difference between the sum and pi) is less than 5e-6 and indicate how many terms there are in the sum and the value of the sum. As a precaution, in case the sum does not converge fast enough, your program should stop when 10**6 terms are added and display a message indicating that the error is not less than 5e-6 after the first 10**6 terms are added. Note that the best floating point approximation of pi is found in math.pi.

You must use print for all displays. You must make the display exactly in the following format:

at 1 term the sum is equal to xxxxxxxxx
at 10 terms the sum is equal to xxxxxxxxx
at 100 terms the sum is equal to xxxxxxxxx
at 1000 terms the sum is equal to xxxxxxxxx
at 10000 terms the sum is equal to xxxxxxxxx
the sum reaches the tolerable error of xxxxxxxxx at xxxxxxxxx terms
the sum is equal to xxxxxxxxx
where xxxxxxxxx is a number. If the tolerable error is not reached, then the second last line must be in this format:

the sum did not reach the tolerable error from xxxxxxxxx to xxxxxxxxx terms.
Your program must use significant identifiers in ASCII camelCase, it must be well indented, without too long lines, and it must be well commented. In short, as if your code will be used by another programmer in the future. Comments should include:

- your name and the date at the beginning of the code
- a brief explanation of the purpose of the code
- an explanation of each variable declared
- an explanation of how the code works (its logic)


It must be easy to modify the error you are looking for. The very first statement of your program must therefore be a variable declaration. This variable must contain the floating number corresponding to the error sought by your program. When you submit, the value 5e-6 must be assigned to this variable, but it must be possible to modify it. Be sure to choose a meaningful identifier for it.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education