CSC105 – Programming Logic
Lab04A:
Pi Approximation: π can be computed using the following Nilakantha formula:
π = 3 + 4/(2*3*4) - 4/(4*5*6) + 4/(6*7*8) - 4/(8*9*10) + 4/(10*11*12)…
or, where t = term, and i = iteration:
π Value |
= |
3 |
3.1666666667 |
3.13333333333 |
3.14523809524 |
3.13968253968 |
Greater than or equal to 3.14 and less than 3.15 |
|||||
t |
= |
|
+ |
4/(2*3*4) |
- |
4/(4*5*6) |
+ |
4/(6*7*8) |
- |
4/(8*9*10) |
+ |
4/((2i)*(2*i+1)*(2*i+2)) |
i |
= |
0 |
1 |
2 |
3 |
4 |
i |
|||||
Notice the pattern in the denominators above, and the sign alternates to its opposite (positive to negative, negative to positive, etc.). This can be coded as a “for” loop where you initialize the variable “sign” as a positive 1 before the loop body, and then multiply it by negative 1 inside the loop to change the sign for each iteration of the loop. Here is a graph of the π values after the first four iterations:
Create a Python program called “PiApproximation.py” that displays the following π value for i = 200, i = 500, and i = 1000. Then, determine exactly which iteration causes the value of π to reflect 3.14159265… In other words, determine when π becomes greater than or equal to 3.14159265 and less than 3.14159266. Print this out at the end of your output (after the values of π are printed out at iterations 200, 500, and 1000). All output should be done using the format() function, and decimals should go to the 10th decimal place.
CS 340 Milestone One Guidelines and Rubric Overview: For this assignment, you will implement the fundamental operations of create, read, update,
Retail Transaction Programming Project Project Requirements: Develop a program to emulate a purchase transaction at a retail store. This
7COM1028 Secure Systems Programming Referral Coursework: Secure
Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip
CS 340 Final Project Guidelines and Rubric Overview The final project will encompass developing a web service using a software stack and impleme