Here’s my problem, I have two different lists, list a which contains the name of people and list b which contains their phone numbers:
a = ["peter", "bob", "john", "jack"]
b = ["8954 3434", "8999 4432", "8976 5443", "8990 3331"]
What I need to do is prompt users for a input which will be a name from list a and then python should automatically print out the phone number for that person from list b.
I came across a code that seems pretty interesting:
for x, y in zip(a, b):
print x, y
This pretty much prints every single name and the corresponding phone number next to it which is basically what I need, however rather than every name from list a appearing, what I need is for the user to be able to enter a single name and for that names phone number to show up.
Just to clarify, using the above code gives me the output:
peter 8954 3434
bob 8999 4432
john 8976 5443
jack 8990 3331
While what I want is for the user to be able to enter a name e.g “peter” which should give the output:
peter 8954 3434
Is there a way to edit that above code to get things to work properly? Thanks for any help.
The most basic way to solve this:
I hope it’s homework.