python - Binary Search Program - TypeError: Can't convert 'int' object to str implicitly -


i've made simple binary program in python java, @ moment i'm new in python(not new i've spent 20 days learn it).

i'm getting error:

enter number of element:  5 traceback (most recent call last):   file "c:\users\raj\documents\eclipseproject\pythonproject1\myprogram.py", line 15, in <module>     print("enter "+int(n)+" elements") typeerror: can't convert 'int' object str implicitly 

here program:

array = []  print("enter number of element: ") n = input() n = int(n)  array = [n]  print("enter "+int(n)+" elements")  in (0, n):     array[i] += input()  print("enter element, want find:") search = input() search = int(search)  first = 0 first = int(first)  last = n-1 last = int(last)  middle = (first+last) / 2 middle = int(middle)  while(first <= last):     if array(middle) < search:         first = middle + 1         first = int(first)      elif array[middle] == search:         print(int(search)+" value found @ location "+int((middle+1)))         break      else:         last = middle - 1         last = int(last)         middle = (first+last)/2         middle = int(middle)  if first>last:     print(int(search)+" not present in list!") 

as tried in program convert integers, still i'm getting same error.

help appreciated!!!

    print("enter "+int(n)+" elements") typeerror: can't convert 'int' object str implicitly 

do see error? try this:

    print("enter "+str(n)+" elements") 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -