Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON CODE PROGRAMMING CSCI 181 Programing Assignment 6 This assignment will be similar to an earlier one where we computed square roots. This time, were

PYTHON CODE PROGRAMMING

CSCI 181 Programing Assignment 6 This assignment will be similar to an earlier one where we computed square roots. This time, were going to compute cube roots. Like before, there is a nice little formula that we can iterate to approximate the answer. It is: x = 2 x 3 + b / 3 x 2

where b is the number we are trying to compute the cube root of. Whats different this time (besides the cube root thing) is that we will use a while loop instead of a for loop. We will iterate in the while loop until we either exceed the maximum number of times we will allow it to loop or until the answer meets an error tolerance that we specify.

You should implement the code for the function specified below: def cubeRoot(b,guess,maxN,tol): #b is the number to find the cube root of #guess is an initial guess #maxN is the maximum number of iterations for the loop #tol is how close to the true answer you want to get #your code will go here To make this assignment more fun, youre not allowed to use any built in Python way to compute the cube root. So how do we estimate how far off we are from the true value? Heres one way. You need to keep track of the previous estimate for the cube root. Well use the absolute value of the difference of the new estimate - the previous estimate as a measure of the error. oldAns = guess while loop:#you have to figure out the condition here newAns = #the code to update the estimate uses oldAns error = abs(oldAns - newAns) #whatever else code you need

Your function should return a list with the best estimate as the first entry, the error estimate as the second entry, and the number of iterations your loop performed as the third entry.You should also write a main function that uses your cube root function. This function should prompt the user for the number they want to take the cube root of, the maximum number of iterations to allow, a guess for the answer, and a tolerance to try to meet. It should also print out the best estimate to the cube root, the error estimate and whether or not the tolerance has been met. I would like for you to turn in a python (.py) file containing both of these functions on Blackboard. I will not accept a picture of the code, a word document, or anything other than the .py file. It really wastes a lot of my time when I am grading your assignments if they arent turned in on Blackboard and/or they are not in the proper file that I can open and run in Python. If you have questions about what to turn in, ask and I will help you get the right file uploade

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David M. Kroenke

12th Edition International Edition

1292023422, 978-1292023427

More Books

Students also viewed these Databases questions

Question

Does it clearly identify what you have done and accomplished?

Answered: 1 week ago