Question

In: Computer Science

Document where I have # to explain what the code is doing. (5 of the 20...

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: ", ________)

Solutions

Expert Solution

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


Related Solutions

Here is what I have so far. I have created a code where a user can...
Here is what I have so far. I have created a code where a user can enter in their information and when they click submit all of the information is shown. How can I add a required field for the phone number without using an alert? <!Doctype html> <html> <head> <meta charset="UTF-8"> <title>Login and Registeration Form Design</title> <link rel="stylesheet" type="text/css" href="signin.css"> <script> function myFunction(){ document.getElementById('demo').innerHTML = document.getElementById('fname').value + " " + document.getElementById('lname').value + " " + document.getElementById('street').value + " "...
I have this mystery code. I dont know what the code does. Can somone please explain...
I have this mystery code. I dont know what the code does. Can somone please explain with examples. (python 3.xx) from typing import Dict, TextIO, Tuple, List def exam(d1: Dict[str, List[int]], d2: Dict[int, int]) -> None: """ *Mystery code* """ for key in d1: value = d1[key] for i in range(len(value)): value[i] = d2[value[i]]   
I just need 3 and 5. I am not sure what I am doing wrong. I...
I just need 3 and 5. I am not sure what I am doing wrong. I get different numbers every time. Superior Markets, Inc., operates three stores in a large metropolitan area. A segmented absorption costing income statement for the company for the last quarter is given below: Superior Markets, Inc. Income Statement For the Quarter Ended September 30 Total North Store South Store East Store Sales $ 4,800,000 $ 960,000 $ 1,920,000 $ 1,920,000 Cost of goods sold 2,640,000...
Okay, can someone please tell me what I am doing wrong?? I will show the code...
Okay, can someone please tell me what I am doing wrong?? I will show the code I submitted for the assignment. However, according to my instructor I did it incorrectly but I am not understanding why. I will show the instructor's comment after providing my original code for the assignment. Thank you in advance. * * * * * HourlyTest Class * * * * * import java.util.Scanner; public class HourlyTest {    public static void main(String[] args)     {        ...
I have to do a presentation where I explain and compare the ratio analysis of the...
I have to do a presentation where I explain and compare the ratio analysis of the IBERDROLA company of years 2015 and 2016, and say at the end if I would like to invest in such a company/business. And comment alittle bit on accounting policies cash flow statement BS IS and notes. The link of this is bellow: https://www.iberdrola.com/wcorp/gc/prod/en_US/corporativos/docs/FinancialStatements_AuditorsReport_Consolidated16.pdf at this link you find everything, also the financial statements, or you can google it
5. Describe what Document Management is
5. Describe what Document Management is
Data mining i have a data column where the required mark is 20 but the data...
Data mining i have a data column where the required mark is 20 but the data fed in to the column is more than 40 , how do you advise me to clean that data, and also please state what data is it for instance noisy or what and also name the method to solve it and please tell how to clean it thanks
I have written code in C programming that checks where the command line arguments are floats...
I have written code in C programming that checks where the command line arguments are floats or not. For example, if I type "./math 1 1 0 0 2.5 3" in the terminal, my program realizes they are all floats but if I type "./math 1 1 0 0 2.5 g", it recognizes that not all arguments are floats and gives an error message. I want to take my code further such that after typing in "./math 1 1 0...
Can you please see what I have done wrong with my program code and explain, This...
Can you please see what I have done wrong with my program code and explain, This python program is a guess my number program. I can not figure out what I have done wrong. When you enter a letter into the program, its supposed to say "Numbers Only" as a response. I can not seem to figure it out.. instead of an error message. import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if...
I have a code and it works and runs as it supposed too. What is the...
I have a code and it works and runs as it supposed too. What is the UML for it? Any help will be awesome. Thanks. import java.util.Scanner; public class StringToMorseCode { public static void main(String[] args){ Scanner input = new Scanner(System.in);    char[] letters = { ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6',...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT