This is a pair assignment worth 20 points.
If you helped anyone else, separately identify them.
Submit a single file to Blackboard, with the naming convention prog1_ID.py where ID is the blackboard ID of the submitter. For instance I would submit prog1_aharrin.py.
Remember to have each team member submit a log to Blackboard also. Your grade will not be final until the log is passed in. The log format is described in the Pairs Administration page: The log should indicate your hours working on the homework and an assessment of your contribution and an assessment of your partner's contribution. Please name the file 150log1ID.doc, where ID is your blackboard ID, and the 1 refers to Program 1, so if I were submitting a log for this assignment, it would be called 150log1aharrin.doc.
The Problem:
This program will implement a well known technique for
approximating the square root of a number.
In general, a positive number can be written as the product of two
positive numbers in an infinite number of ways.
For example,
36 = 1 * 36 = 2*18 = 3* 12 = 4* 3 = 5 * 7.2 = 6 * 6 = 10*3.6 = 16 * 2.25 etc.
If the factors are the same, then use have found the square root. Notice that when one factor is larger than the square root, the other one is smaller. So one way to proceed is to choose one factor of a number, calculate the other by dividing. Generally they will be different. Since we want to find two equal factors, the next choice for the first factor can be the average of the two we found. Each time through this loop we get a better approximation. You can start your first guess with 1.0 if you want. (The decimal point is important to avoid integer arithmetic.)
For example, if we try 5 steps on the number 36, starting from the initial guess 1.0, then the next five approximations areYour program should
Note 1: This is the best we can do with the amount of Python introduced so far. It would make more sense to automatically repeat this process until the answers do not change, but we have not studied that kind of loop yet.
Note 2: Math may not be your favorite thing, but at least it is better to have Python doing the calculations rather than you! We are doing numerical things first because they are particularly easy to introduce. As we introduce more of Python, we will go on to processing text and producing graphics, web pages, ....