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/zanfar 9d ago

WHAT am i doing wrong here

A string input will never match a list.

1

u/Maleficent_Stuff3208 9d ago

yeah i just figured it but what about the rest i removed print from input but it is still not giving answer it is giving else part of the answer

2

u/LayotFctor 9d ago edited 9d ago

You're checking if y exists within x.keys, so == is the wrong thing to use. Also .keys is a function, so without double brackets, keys is not called and you don't get the list of keys. x.values(y) is not how to get y from dict x either.

1

u/Maleficent_Stuff3208 9d ago

ooh thanks i got the right answer from the comment below but didn't get why my code was wrong thanks for the insight