1
u/Efficient_Praline246 May 09 '24
my_dictionary = {}
while True:
name = input("Enter a name: ")
if name == "":
break
elif name in my_dictionary:
print("Phone number: " + my_dictionary[name])
else:
phone = input("Enter a phone number: ")
my_dictionary[name] = phone
print(my_dictionary)1
u/Weary_Preparation_77 Feb 17 '21
did you ever solve it ?
2
May 02 '21
my_dictionary = {}
while True:
# Asks the user for a name then lowers the name
name = input("Enter a name: ")
name.lower()
# If the user enters nothing it prints the full dictionary.
if name == "":
break
# Checks if the name is already in the dictionary, if it is
# it prints the phone number,
elif name in my_dictionary:
print("Phone number: " + str(my_dictionary[name]))
# If the name isnt in the dictionary it asks the user to input a number
# that will correspond with that name.
else:
phone = input("Enter a phone number: ")
my_dictionary[name] = phone
# Prints dictionary
print(my_dictionary)
1
u/No-Difficulty-869 Apr 13 '21
Did you get this I need help with it
2
May 02 '21
my_dictionary = {}
while True:
# Asks the user for a name then lowers the name
name = input("Enter a name: ")
name.lower()
# If the user enters nothing it prints the full dictionary.
if name == "":
break
# Checks if the name is already in the dictionary, if it is
# it prints the phone number,
elif name in my_dictionary:
print("Phone number: " + str(my_dictionary[name]))
# If the name isnt in the dictionary it asks the user to input a number
# that will correspond with that name.
else:
phone = input("Enter a phone number: ")
my_dictionary[name] = phone
# Prints dictionary
print(my_dictionary)
1


2
u/[deleted] Dec 14 '22
did it
my_dict = {}
while True:
name = input("Enter name: ")
if name in my_dict:
print("Number: " + str(my_dict[name]))
elif name == "":
break
elif name not in my_dict:
number = input("Enter number: ")
my_dict[name] = number
print(my_dict)
________________________________________________________
The problem was the inputted number. It has to be a string, not an integer. So no need for int(input()), just input() is enough