python - simple linear search program that is not giving desired output -
def linear_search(): a= raw_input("ënter list") = a.split() a_len = len(a) num = int(input("ënter no searched ")) in range(a_len): if a[i]== num: print("no found") else:`enter code here` print("no not found") linear_search() this program giving o/p eg if = ['12','13','16'] , num = 16 return o/p no not found no not found no not found please find error in program , using 2.7 version of python
16 not equal '16'.
>>> 16 == '16' false convert list of strings list of ints. can iterate through elements of list , convert them int individually. this:
a = raw_input("ënter list") list_a = [int(i) in a.split()] or use map() after inputting list user with:
a = raw_input("ënter list") list_a = map(int, a.split())
Comments
Post a Comment