This code is to have a dictionary of names and birthdays.
It will ask who's birthday it is that you're looking for. Then if it is in the dictionary, it will print back what that birthday is. If not, it will ask if you want to add it then have you insert the birthday as the value and use the name that you input before as the key. Then finally print the full dictionary.
I am pretty new to coding in Python and feel like there is a better way to type this code. Was thinking I could use return but I'm still not quite sure what the difference between return and print is. Is there a way to make this shorter or more efficient?
birthdays = {'Jon': 'July 17', 'Shauna': 'Jan 27', 'Lynette': 'July 10'}
while True:
print("Who's birthday is it that you are looking for? To cancel, press enter!")
name = input()
if name == '':
break
if name in birthdays:
print(birthdays[name] + ' is the birthday of ' + name)
else:
print("I don't have that person's name in my archives. Would you like to add it? Press Y or N")
answer = input()
if answer == 'Y':
new_name = name
print("Please enter their birthday")
new_birthday = input()
birthdays[name] = new_birthday
print('It has been added')
print(new_name + "'s birthday has been added as " + new_birthday)
print('Here is a list of birthdays you have saved...')
print(birthdays)
else:
print('Alrighty Then')
return birthdays
in the context of a function which is called elsewhere and print's the result. Other function won't have access to what's printed on the screen from your code. \$\endgroup\$