26.8k views
1 vote
Does anyone happen to have the answer to the CodeHS Python Exercise 5.4.7: Categories. A version that is available to be copied and pasted would be nice.

User Humkins
by
7.0k points

1 Answer

4 votes

Answer:

# empty dictionary to hold the category

dictionary = {}

# user is prompt to enter category 1

category1 = input("Enter category1: ")

# user is prompt to enter category 2

category2 = input("Enter category2: ")

# user is prompt to enter category 3

category3 = input("Enter category3: ")

# empty list for category 1

category1_item = []

# loop to accept 3 items for category1

for i in range(3):

item = input("Enter item in the category1: ")

category1_item.append(item)

# category1 item is assigned to category1

dictionary[category1] = category1_item

# empty list for category2

category2_item = []

# loop to accept 3 items for category2

for i in range(3):

item = input("Enter item in the category2: ")

category2_item.append(item)

# category2 item is assigned to category2

dictionary[category2] = category2_item

# empty list for category 3

category3_item = []

# loop to accept 3 items for category3

for i in range(3):

item = input("Enter item in the category3: ")

category3_item.append(item)

# category3 item is assigned to category 3

dictionary[category3] = category3_item

# loop throughout the dictionary to

# print each category and its item.

for key, value in dictionary.items():

print(key, ":", value)

Step-by-step explanation:

Complete Question is:

5.4.7: Categories. Write a program that asks the user for three categories. For each category, ask the user for three things in that category. You should print something for each category that states the category and the three things in that category.

The program is written in Python and well commented.

User Chris Wagner
by
6.6k points