Reference no: EM133091503
Debugging
Exercises
Task 1. In this task you are required to implement the Babylonian square-root algorithm. It was known to the ancient Babylonians (1500 BC) and Greeks (100 AD) .
Here's how it works. Suppose you are given any positive number n. To find the square root of n, do the following:
1. Make an initial guess. Guess any positive number s0.
2. Improve the guess. Apply the formula s1 = (s0 + n / s0) / 2. The number x1 is a better approximation to sqrt(n).
3. Iterate until convergence. Apply the formula sk+1 = (sk + n / sk) / 2 until the process converges.
Your task is to write a function, babylon_sqrt(n, guess, iterations), that takes three arguments - the number n, the initial guess, and the number of iterations and returns (hopefully a good) approximation of square root of n.
Task 2. Re-write the babylon_sqrt function, so that if any of the three arguments is a non-positive number it raises a custom exception named BadNumberException. Write a small program to test your solution.
Task 3. In your own words, explain why you should use logging to help debug your programs instead of using the print statement?
Also, write a small program that uses Python's logging module to log five different log messages, each with different levels of importance (debug, info, warning, error, critical).Task 4. Our final activity for today will be to experiment with the Python debugger, which is called pdb.
Task 4. Our final activity for today will be to experiment with the Python debugger, which is called pdb.
Attachment:- Debugging.rar