hi I m wrtng a very simple Python Program to implement Binary Search.
tup=input("enter tup:")
start=0
length=len[tup]
end=tup[length-1]
mid=(int(start)+int(end))/2
key=input("enter value to search")
def search(start,end,key):
if key==tup[mid]
print mid
else if key<tup[mid]
search(start,mid,key)
else if key>tup[mid]
search(mid,end,key)
else
return(-1)
I get an error as
File "binsearch.py", line 8
if key==tup[mid]
^
SyntaxError: invalid syntax
I believe I m missing something trivial but unable to figure out.! Let me know if u feel there are any other errors. thanks 🙂
:(i.e. the statements where you increase the indentation level in the next line)else if Xwithelif X:raw_inputinstead ofinputas the latterevals whatever the user entered.returnis a statement, not a function, so you do not need()around the return value.