0

I was supposed to write the script of linearSearch in a list (To find an item) in Python. I did the code in Jupyter Notebook but i got the error below and don't know why i am getting this error. Can anyone tell me how i solve the error?

Here is the code:

def linearsearch(myitem,mylist):
    Found = False
    position= 0
    while position < len(mylist) and not Found:
        if mylist[position] == myitem:
            Found = True
    position = position + 1
    return Found

if __name__ == "__main__":
    shoppinglist=["Apple","Orange","Banana"]
    item = input("what item are u looking for?")
    isitfound = linearsearch(item,shoppinglist)
    if isitfound:
        print("item is in the list")
    else:
        print("the item is not in the list")

When i run the code i got the line "what item are u looking for?". But when i enter an item in the list for example Apple i get the error below:

    163             self._sys_eval_input = builtin_mod.input
    164             builtin_mod.raw_input = self.raw_input
--> 165             builtin_mod.input = lambda prompt='': eval(self.raw_input(prompt))
    166         self._save_getpass = getpass.getpass
    167         getpass.getpass = self.getpass

NameError: name 'Apple' is not defined
user8034918
  • 441
  • 1
  • 9
  • 20

0 Answers0