I want to make a program, where in a dictionary, I put in peoples names and their email addresses, and when the user puts in a name it gives back the email. Is their a quicker way to do that other than doing a whole lot of if
loops or maybe a for
loop? Any ideas?
CodePudding user response:
d = {'Alice': '[email protected]', 'Bob': '[email protected]'}
user_input = input('Input a name:').lower().capitalize()
if user_input in d:
print(d[user_input])
If inputting Bob, (irrespective of capitalization), this prints
Input a name:Bob
[email protected]