Hi guys Im new to python coding, and am practicing with lists and dict. I have a code where each name has a set number, and when I enter the name their number gets print out.
name_list = ["bob","jim","james","julie","june"]
number_list = ["1","2","3","4","5"]
name_and_number = dict(zip(name_list, number_list))
def namenumb(something):
try:
print("{}'s number is {}".format(
something, name_and_number[something]))
except KeyError:
print("That name doesn't exist"
.format(namenumb))
while True:
word = input("> ")
namenumb(word)
However, I want it to work the other way around aswell, so when I type a number in their name gets printed out. How would I do that?
Thanks
while True:is not a great idea without at least anybreaks in the loop.