subject

Instructions Restructure Newton's method (Case Study: Approximating Square Roots) by decomposing it into three cooperating functions. 1 import nath 2 from nath import 3sqrtofThis float(input("Enter a posttive number 4 theSqrt- math. sqrt (sqrtof This) 5 toler000061 6 def limit_reach() The newton function can use either the recursive strategy of Project 2 or the iterative strategy of the Approximating Square Roots Case Study. The task of testing for the limit is assigned to a function named linitReached whereas the task of computing a new approximation is assigned to a function named inproveEstimate. Each function expects the relevant arguments and returns an appropriate value pass 8 f diffvaltoler unny-1 18 else unny-0 inproveEstinate() 12 def 14 15 16 17 18 19 28 21 def main): 22 qrt Estinate-improveEstimate) 23nproveEstinate() 24 print (str(sqrt Estimate) is the progran estimated square root of "+ sgrt Estinate1 while True: sqrt_Estimate-(sqrt_Estinate sqrtofThis/sqrt_Estinate)/2 diffvalsqrt Estinate-theSqrt if diffvaltoler An example of the program input and output is shown below: break return sqrt_Estinate Enter a positive number or enter/return to qu The program's estinate is 1.4142135623746899 Python's estinate is Enter a positive number or enter/return to qu 1.4142135623730951 str(sqrt_Of_ This) per Newtons Method") 25 26 print (str(theSqrt)is Python estimated calculation of the square root of'+ Grading Run Code Test Grade As you complete the instructions above you

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 12:10, Geo777
1. package newton’s method for approximating square roots (case study 3.6) in a function named newton. this function expects the input number as an argument and returns the estimate of its square root. the script should also include a main function that allows the user to compute square roots of inputs until she presses the enter/return key. 2. convert newton’s method for approximating square roots in project 1 to a recursive function named newton. (hint: the estimate of the square root should be passed as a second argument to the function.) 3. elena complains that the recursive newton function in project 2 includes an extra argument for the estimate. the function’s users should not have to provide this value, which is always the same, when they call this function. modify the definition of the function so that it uses a keyword parameter with the appropriate default value for this argument, and call the function without a second argument to demonstrate that it solves this problem. 4. restructure newton’s method (case study 3.6) by decomposing it into three cooperating functions. the newton function can use either the recursive strategy of project 1 or the iterative strategy of case study 3.6. the task of testing for the limit is assigned to a function named limitreached, whereas the task of computing a new approximation is assigned to a function named improveestimate. each function expects the relevant arguments and returns an appropriate value. 5. a list is sorted in ascending order if it is empty or each item except the last one is less than or equal to its successor. define a predicate issorted that expects a list as an argument and returns true if the list is sorted, or returns false otherwise. (hint: for a list of length 2 or greater, loop through the list and compare pairs of items, from left to right, and return false if the first item in a pair is greater.)
Answers: 1
image
Computers and Technology, 22.06.2019 17:30, jonquil201
Where would you click to edit the chart data?
Answers: 1
image
Computers and Technology, 22.06.2019 22:00, lgary9462
Perform the following tasks: a. create a class named testclass that holds a single private integer field and a public constructor. the only statement in the constructor is one that displays the message “constructing”. write a main()function that instantiates one object of the testclass. save the file as testclass. cpp in the chapter 08 folder. run the program and observe the results. b. write another main()function that instantiates an array of 10 testclass objects. save the file as test class array. c . run this program and observe the results.
Answers: 1
image
Computers and Technology, 23.06.2019 18:00, yedida
File account. java (see previous exercise) contains a definition for a simple bank account class with methods to withdraw, deposit, get the balance and account number, and return a string representation. note that the constructor for this class creates a random account number. save this class to your directory and study it to see how it works. then write the following additional code: 1. suppose the bank wants to keep track of how many accounts exist. a. declare a private static integer variable numaccounts to hold this value. like all instance and static variables, it will be initialized (to 0, since it’s an int) automatically. b. add code to the constructor to increment this variable every time an account is created. c. add a static method getnumaccounts that returns the total number of accounts. think about why this method should be static - its information is not related to any particular account. d. file testaccounts1.java contains a simple program that creates the specified number of bank accounts then uses the getnumaccounts method to find how many accounts were created. save it to your directory, then use it to test your modified account class.
Answers: 3
You know the right answer?
Instructions Restructure Newton's method (Case Study: Approximating Square Roots) by decomposing it...

Questions in other subjects: