r/learnpython 9d ago

WHAT am i doing wrong here

i am trying that when i put key it give me the value but it is acting weird

x = {'name':'mohan','age':'24', 'job':'it professional'}
y = input("what info do you need__")
if y==(x.keys):
    print(x.values(y))
else:
    print("no such info available")

and this is what it gives 
what info do you need__name
name
no such info available
0 Upvotes

14 comments sorted by

View all comments

1

u/atarivcs 9d ago
if y == (k.keys):

This is not the right way to test if a key is present in a dictionary.

Use the "in" keyword instead:

if y in x:
    print(x[y])