Implement the babylonian square-root algorithm

Assignment Help Other Subject
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

Reference no: EM133091503

Questions Cloud

Advantages and disadvantages to implement vmi : Please define Vendor-Managed-Inventory (VMI). Discuss the advantages and disadvantages to implement VMI?
When would you need to modify a policy : When would you need to modify a policy? And why should you review your policy on a regular basis?
Performance indicators to measure success of online strategy : Identify a company that could benefit from better use of social media. Determine key performance indicators to measure the success of the online strategy.
Small group of entertainment celebrities : The fine-dining restaurant (which is owned by a small group of entertainment celebrities) you have just been hired to manage is struggling with inventory issues
Implement the babylonian square-root algorithm : Implement the Babylonian square-root algorithm. It was known to the ancient Babylonians (1500 BC) and Greeks (100 AD)
What is the portfolio standard deviation : Question - Given the following information: What is the portfolio standard deviation
How can we enhance information security in legal settings : How can we enhance information security in legal settings?
How can the areas success be measured : 1. How can the areas success be measured? 2. How can output be maximized or improve?
Diversifying businesses to tune money : Analyse the challenges of Air Asia in diversifying their businesses to Tune Money.

Reviews

Write a Review

Other Subject Questions & Answers

  Cross-cultural opportunities and conflicts in canada

Short Paper on Cross-cultural Opportunities and Conflicts in Canada.

  Sociology theory questions

Sociology are very fundamental in nature. Role strain and role constraint speak about the duties and responsibilities of the roles of people in society or in a group. A short theory about Darwin and Moths is also answered.

  A book review on unfaithful angels

This review will help the reader understand the social work profession through different concepts giving the glimpse of why the social work profession might have drifted away from its original purpose of serving the poor.

  Disorder paper: schizophrenia

Schizophrenia does not really have just one single cause. It is a possibility that this disorder could be inherited but not all doctors are sure.

  Individual assignment: two models handout and rubric

Individual Assignment : Two Models Handout and Rubric,    This paper will allow you to understand and evaluate two vastly different organizational models and to effectively communicate their differences.

  Developing strategic intent for toyota

The following report includes the description about the organization, its strategies, industry analysis in which it operates and its position in the industry.

  Gasoline powered passenger vehicles

In this study, we examine how gasoline price volatility and income of the consumers impacts consumer's demand for gasoline.

  An aspect of poverty in canada

Economics thesis undergrad 4th year paper to write. it should be about 22 pages in length, literature review, economic analysis and then data or cost benefit analysis.

  Ngn customer satisfaction qos indicator for 3g services

The paper aims to highlight the global trends in countries and regions where 3G has already been introduced and propose an implementation plan to the telecom operators of developing countries.

  Prepare a power point presentation

Prepare the power point presentation for the case: Santa Fe Independent School District

  Information literacy is important in this environment

Information literacy is critically important in this contemporary environment

  Associative property of multiplication

Write a definition for associative property of multiplication.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd