Below is a Python script that approximates the positive square root of positive integers. The algorithm makes guesses by continually averaging the upper and lower bound of a range of numbers that dynamically adjusts.
## Number we seek the sqrt ofn=input("Find sqrt of: ")## input() gets input from the console## Set the boundsupperBound=nlowerBound=0## Acceptable variation in resultdelta=0.00001## Current guess at sqrt of nguess=(upperBound+lowerBound)/2.0## Checks if guess*guess is within +/- delta of nwhileguess*guess<n-deltaorguess*guess>n+delta:## Resets bounds according to outcomeifguess**2<n-delta:lowerBound=guesselse:upperBound=guessguess=(upperBound+lowerBound)/2.0test=int(guess+0.5)## int() casts other number types into integersiftest**2==n:guess=testprintguess
Analyze the script and determine the error that exists in it from the choices below.
Excel in math and science
Master concepts by solving fun, challenging problems.
It's hard to learn from lectures and videos
Learn more effectively through short, interactive explorations.
Used and loved by over 6 million people
Learn from a vibrant community of students and enthusiasts,
including olympiad champions, researchers, and professionals.
Your answer seems reasonable.
Find out if you're right!