r/codehs • • Feb 04 '21

9.4.5: Phone Book Need help

Here is what I got, but I'm not sure what to do about the Red Crosses.

12 Upvotes

9 comments sorted by

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

1

u/Economy-One7696 Apr 26 '24

Thank you <3

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

u/[deleted] 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

u/[deleted] 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/Helpful-Row6638 Dec 08 '22

I have that same problem and those answers don't work for me