Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search age of person in dictionary

Tags:

python

I have a function that asks for the person their first and last name and then prints their age but i am having trouble entering the if statement, it is always skipping it.

My dictionary prints like this on the command line: {('name','subname'):19)}

l_name = raw_input("Enter last name")
f_name = raw_input("Enter first name")
if (l_name, f_name) in my_dict.items():
    age = my_dict[l_name,f_name]
    print age

thanks in advance

like image 426
user998316 Avatar asked Nov 28 '25 13:11

user998316


1 Answers

Try this:

if (l_name, f_name) in my_dict:

See it working online: ideone

like image 155
Mark Byers Avatar answered Nov 30 '25 04:11

Mark Byers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!