0

I have created a dictionary and given some arbitrary keys and values. I want the user to input the name he wants to search for in my dictionary and I have created a loop to search for that name using linear search to print found or not found using the below code:

person = dict()
person["Ravi"] = "789"
person["Ram"] = "850"
person["Raju"] = "995"
print(person)
name = input()
y = None
for key in person.keys():
    if key == name:
        print("found")
    else:
        y = False
if not y:
    print("Not found")

but my program is printing Not found every time even though I enter some name which is existing in keys like Ravi exactly in same case. can anyone please find any bug in this code causing this error?

0 Answers0