
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question

Transcribed Image Text:Overview
One of the oldest methods for computing the square root e of a number is the Babylonian Method e. The Babylonian Method uses an iterative algorithm to make successively more accurate
estimates of a number's square root. The algorithm stops iterating when the estimate shows no further sign of improvement, or when the estimate is within some acceptable margin of error.
The acceptable margin of error is often called an epsilon.
Assuming that you need to solve for the square root of x, the algorithm works as follows.
1. Choose an epsilon value that determines how close your solution should be to the actual square root value before you decide it is "good enough." Because this assignment asks you to solve
for the square root to three decimal places, we can safely set the epsilon value to 0.0001 (four decimal places). This guarantees that our solution will be accurate to the precision we need to
display to the screen.
2. Choose an initial estimate e for the square root of x. An easy and perfectly valid approach is to set the initial estimate e=x. For example, you could set the first estimate for the square root of
4 to be 4.
3. Evaluate the estimate by dividing the value x by your estimate e, and comparing the result of that division to the current estimate e. If your estimate e were to be exactly equal to the square
root, then you would find that x/e=e. In practice, unless you are lucky, there will typically be some difference between these two values (x/e and e) even after many iterations of the
algorithm.
4. Determine if the estimate is "good enough" to stop. A smaller difference between x/e and e reflects a more accurate estimate. If the difference is smaller than your epsilon value, then
you've found the answer! If not---if the difference is greater than the epsilon value---then you need to proceed to step 5 below.
Note that you'll want to look at the absolute value of the difference between x/e and e. This is because e may be too large or too small. To test for the absolute value, you could use if/else
logic to see which term (x/e or e) is smaller. You could then subtract the smaller value from the larger one. Alternatively, you could use the Python's built-in function abs().
5. Revise the estimate (if needed based on Step 4) by setting e to the average of the fraction x/e and your old estimate e. Using this new estimate, go back to Step 3.
For this assignment, you need to write a Python program that solves for square roots using the algorithm outlined above. See the requirements sections below for more detailed instructions.
Please Note that you are not allowed to use any built-in functions for this assignment while Python has its own way of calculating square roots. Instead, you must implement your own solution
to this classic mathematical problem. To be clear, you should NOT use any pre-defined Python square root function anywhere in your assignment solution.
Requirement
You need to implement the Babylonian Method for computing square roots. Based on that core functionality, you are to write an interactive program that:
Prompts the user to enter an integer value above zero.
• Checks to ensure that the value is indeed above zero. If not, the program displays an error message and asks for the input again.
Computes the square root of the value using the Babylonian Method outlined above.
Displays the square root to the user formatted to show exactly 3 decimal places (no more than 3, and no less than 3).
Satisfying all basic requirements perfectly, with no points deducted for any reason, would earn a maximum score of 50 out of 50 for this assignment.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- The following problem shows up in a number of Java texts, including Savitch's textbook: The Harris-Benedict equation estimates the number of calories your body needs to maintain your weight if you do no exercise. This is called your basal metabolic rate, or BMR. The calories needed for a woman to maintain her weight is: WBMR = 655 + (4.3 × weight in pounds) + (4.7 × height in inches) − (4.7× age in years) The calories needed for a man to maintain his weight is: MBMR = 66 + (6.3 × weight in pounds) + (12.9 × height in inches) − (6.8 × age in years) A typical chocolate bar will contain around 230 calories. Write a program that allows the user to input his or her weight in pounds, height in inches, and age in years. The program should then output the number of chocolate bars that should be consumed to maintain one’s weight for both a woman and a man of the input weight, height, and age. NOTE: This is an application of a selection statement! Input Data: Use a named constant for the…arrow_forwardUsing pythonarrow_forwardJava Calculating the User's Sum Write a complete program that reads in numbers and calculates the sum of the numbers in that range. Code Specifications In the main method, read input from the user. Read in two integers from the user: a lower end of the range and an upper end of the range. Check if the numbers are valid: the lower number cannot be greater than the upper number. If the numbers are invalid, use a loop to ask for new numbers. Continue looping until you get two valid values. Write a method called calculateTheSum. The method takes in a lower and upper end of the range. The method calculates the sum of all values from lower (inclusive) to upper (inclusive). Invoke the method from main the output the result. Test Cases I recommend testing your code using the test cases below. I've listed the user inputs along with a sample of the result. User Inputs Result lower = 10, upper = 1 the program should ask for new input lower = 5, upper = -5 the program should ask…arrow_forward
- Design and implement an application that plays the Hi-Lo guessing game with numbers. The program should pick a random number between 1 and 100 (inclusive) and then repeatedly prompt the user to guess the number. On each guess, report to the user that he or she is correct or that the guess is high or low. Continue accepting guesses until the user guesses correctly or chooses to quit. Use a sentinel value to determine whether the user wants to quit. Count the number of guesses, and report that value when the user guesses correctly. At the end of each game (by quitting or a correct guess), prompt to determine whether the user wants to play again. Continue playing games until the user chooses to stop.arrow_forwardThis example creates a program to teach a first grade child how to learn subtractions. The program randomly generates two single- digit integers number1 and number2 with number1 > number2 and displays a question such as "What is 9 – 2?" to the student. After the student types the answer, the program displays a message to indicate whether the answer is correct.arrow_forwardin Java languagearrow_forward
- Java - Musical Note Frequenciesarrow_forwardThe text presented the Sierpinski triangle fractal. Inthis exercise, you will write a program to display another fractal, called the Kochsnowflake, named after a famous Swedish mathematician. A Koch snowflake iscreated as follows:1. Begin with an equilateral triangle, which is considered to be the Koch fractalof order (or level) 0, as shown in Figure a.2. Divide each line in the shape into three equal line segments and draw an outwardequilateral triangle with the middle line segment as the base to create aKoch fractal of order 1, as shown in Figure b.3. Repeat Step 2 to create a Koch fractal of order 2, 3, . . . , and so on, as shownin Figures c and d.arrow_forwardHelp me debug this exercise using Javaarrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education