In: Computer Science
Document where I have # to explain what the code is doing. (5 of the 20 points will be for documenting)
Fill in the __ and __________ spaces to complete the code.
Logic
"""
This program approximates the value of pi using an algorithm
designed by the German mathematician Gottfried Leibniz. The
algorithm is as follows:
pi = 4 - 4 / 3 + 4 / 5 - 4 / 7 + . . .
This program allows the user to specify the number of
iterations
to use in the approximation.
"""
#
import __________
#
iterations = __________
pioverfour = ___
numerator = ___
denominator = ___
#
for count in range(__________:
"""equation using varibles""""
numerator = __numerator
denominator __= __
#
print("The approximation of pi is", __________)
print("Compare this to the computer's estimation: ", ________)
Please let me know if anything is required. Please follow the indentation as shown in the code screenshot
Code screenshot:
Sample output1:
Sample output2:
Sample output3:
Sample output4:
Sample output5:
Copyable code:
"""
This program approximates the value of pi using an algorithm
designed by the German mathematician Gottfried Leibniz. The
algorithm is as follows:
pi = 4 - 4 / 3 + 4 / 5 - 4 / 7 + . . .
This program allows the user to specify the number of
iterations
to use in the approximation.
"""
#
import math
#
iterations = input("Enter number iterations: ")#taking the number
from the user for the iterations
pioverfour = 0
numerator = 4
denominator = 1
computerPi=math.pi #computer generated pi value
#
for count in range(int(iterations)):#calculating pi value
"""equation using varibles"""
if(count%2==0):
pioverfour=pioverfour+(numerator/denominator)
else:
pioverfour=pioverfour-(numerator/denominator)
numerator = 4
denominator+=2
#
print("The approximation of pi is", pioverfour)#printing the
calculated pi value
print("Compare this to the computer's estimation: ",computerPi
)#printing the pi value from the computer