I'm a beginner that is currently working on a program with Python for fun and I am attempting to complete a linear search for a given list. Instead of the program returning the index of the value that is being searched for in the list, it is returning the else condition.
I created another function which is called getVal and this is so that the output of getVal will be passed into the linear search function as one of the parameters/arguments.
How would I be able to correct this so that the index number of the value being searched for in the linear search function will be the output? Any help will be greatly appreciated.
def getVal():
userNum = int(input("Enter a number: "))
return userNum
if userNum != int:
get Val
def linearSearch(searchList, getVal):
for i in range(len(searchList)):
if i == getVal:
return searchList.index(i)
else:
return "Value not found"
getVal()
linearSearch(searchList, getVal)
searchList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]