# Dictionary Practice Problems - Solutions # Problem 1 prob1 = {} prob1["a"] = 1 prob1["b"] = 1 prob1["c"] = 1 print(prob1) # Problem 2 prob2 = {} for i in range(1, 6): prob2[i] = i + 1 print(prob2) # Problem 3 message = "once upon a time there was a dog" prob3 = {} pos = 0 for word in message.split(" "): prob3[word] = pos pos = pos + 1 print(prob3) # Problem 4 animals = { "dog": 9, "cat": 4, "frog": 2, "bear": 4, "whale": 10 } total = 0 for animal in animals: # iterates through the keys in animals total = total + animals[animal] print(total) # Problem 5 people = { "Alice": { "age": 20, "height": 62, "weight": 120.0 }, "Bob": { "age": 17, "height": 68, "weight": 130.5 }, "Freddie": { "age": 21, "height": 74, "weight": 190.6 } } prob5 = {} for name in people: # iterates through the keys in people prob5[name] = people[name]["height"]/people[name]["weight"] print(prob5)