a variable named high which we instantiated at 99 and prompted the user to pick

# A variable named high which we instantiated at 99 and

This preview shows page 5 out of 5 pages.

a variable named high which we instantiated at 99, and prompted the user to pick a number for which they wanted to find the square root of, which we stored in a variable named “nr”. Next we created a while loop that stops when the guess equals the actual square root of the number. In the while loop we started off by randomizing a value for our guess variable between lo and high. If our guess was higher than the actual square root then we changed the high variable to equal the guess. If it was too low then we made the lo variable equal to the guess. Once the guess finally equals the real square root then we end the while loop and print the original number the user entered and the guess and the real square root of the number. (c) Describe any difficulties encountered, but you overcame. Some difficulties I encountered during this program was finding a way to get the guess to exactly match the actual square root. I overcame this however when I found out about the round method which allowed me to make the real square root only go to 15 decimal places which is also what I rounded my guess to. (d) Describe any difficulties you encountered that you could not overcome. Some difficulties that I encountered that I could not overcome was trying to accomplish the program with a for loop. I soon realized, however, that the while loop was perfect for this situation.

#### You've reached the end of your free preview.

Want to read all 5 pages?

• Winter '15
• Aisha
• Approximation, partner, Irrational number, Rayan Ali