@KK998/

Bisection Sort with python

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# The number we test
x = 6
epsilon = 0.01
numGuesses = 0
low = 0.0
high = x
ans = (high + low) / 2.0

while abs(ans**2 - x) >= epsilon:
  print("low =", str(low),"high =",str(high),"ans =", str(ans))
  numGuesses += 1
  if ans**2 <x:
    low = ans
  else:
    high = ans

  ans = (high + low) / 2.0
print("numGuesses =", str(numGuesses))
print(str(ans),"is close to the square root of", str(x))