python - the code for linear sequential search is working for single digit numbers but its not working for two digit no -


def search(arr, x):    in range(len(arr)):        if arr[i] == x:           return       return -1    num=input("enter elements\n") input_numbers_list = [int(n) n in num.split()]  value=input("enter element searched") print(input_numbers_list) print(value) = search(num,value) if -1:    print("element not found") else:    print("element found @ specific position "+str(i)) 

right pass strings search. iterate on characters in input string, , check if character equals second string. consider this:

'12345'[2] == '3' 

convert value int:

value = int(input('enter element searched')) 

pass integers search, not input:

i = search(input_numbers_list, value) 

Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -