0
a=[]
f=0

print("BINARY SEARCH")
print("ENTER NUMBERS IN ASCENDING ORDER")
for i in range(0,9):
    k=int(input("ENTER THE ELEMENT AT ["+ str(i+1) +"]: "))
    a.append(k)
s=int(input("ENTER A NUMBER TO BE SEARCHED: "))
#print(a[1])
#exit()
l=0
u=9
while[ l <= u ]:
    m=int( (l + u) / 2)
    if s==a[m]:
        f=1
        break
    elif s>a[m]:
        l = m + 1
    else:
        u = m - 1

if f==1:
    print("FOUND "+str(s)+" at location "+str(m+1))
else:
    print("NOT FOUND")

"NOT FOUND DOES NOT WORK"

2
Contributors
1
Reply
19
Views
4 Years
Discussion Span
Last Post by pyTony
0

You have list with value for while condition, which is never empty, so this while never terminates in case of not found. Remove []

No need to shout with CAPITALIZEd words.

Edited by pyTony

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.