Question

Create a new dictionary called quantities using {} format like. Complete the following: Put these values...

Create a new dictionary called quantities using {} format like.

Complete the following:

  1. Put these values (quantity, price) in your quantities dictionary:
  • "baskets": (4, 2.49)
  • "boxes": (2, 1.95)
  • "bags": (5, 1.29)
  • "crates": (3, 5.99)
  1. Print the quantities dictionary
  2. Loop through each key in quantities. For each key, print out the key along with its corresponding quantity. Print the answer in the following format:
  • baskets: 4
  • boxes: 2
  • bags: 5
  • crates: 3
  1. Print the total number of items (should be 14).
  2. Print the total cost of all items (should be 38.28).

Homework Answers

Answer #1
quantities = {}
quantities["baskets"] = (4, 2.49)
quantities["boxes"] = (2, 1.95)
quantities["bags"] = (5, 1.29)
quantities["crates"] = (3, 5.99)

print(quantities)

for item, data in quantities.items():
    print("baskets:", data[0])

count = 0
total_cost = 0
for item, data in quantities.items():
    count += data[0]
    total_cost += data[0] * data[1]
print(count)
print(total_cost)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT