I am trying to complete this function but to no avail because the dictionary contains float values that I am trying to total up.
Here's the code I have so far:
def add_prices(basket):
# Initialize the variable that will be used for the calculation
total = 0
# Iterate through the dictionary items
for groceries, prices in basket.items():
# Add each price to the total calculation
for price in prices:
# Hint: how do you access the values of
# dictionary items?
total += price.values()
# Limit the return value to 2 decimal places
return round(total, 2)
groceries = {"bananas": 1.56, "apples": 2.50, "oranges": 0.99, "bread": 4.59,
"coffee": 6.99, "milk": 3.39, "eggs": 2.98, "cheese": 5.44}
print(add_prices(groceries)) # Should print 28.44
I'm completely dumbfounded tbh and need help, as tried typecasting to directly assigning the price to the values.