Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

NAME_________________________________

Below is a code that applies dictionary. Your task is to make a description to each of the underlined codes and
Illustrate the final output when this is executed. Write your answer on the space provided

1. fruit_prices = {"apple": 50.00,"banana": 2. adds a new key-value "grape" : 150.00


20.00,"cherry": 80.00,"mango": 80.00} 3. removes the key "cherry" and its corresponding
2. fruit_prices["grape"] = 150.00 value . This value is stored in rem
3. rem = fruit_prices.pop("cherry") 5. updates the value of "mango"to 90.00
4. print (rem)
6. get() returns "Not available"and stores it in
5. fruit_prices["mango"] = 90.00
cherry_price.
6. cherry_price = fruit_prices.get("cherry", "Not
available") 8. prints all the keys in the fruit_prices
7. print(f"Cherry price: {cherry_price}") 9. prints the number of key-value pairs in the
8. print((fruit_prices.keys())) fruit_prices
9. print(len(fruit_prices)) 11. adds each value of the dictionary to the variable
10. sum = 0 sum.
11. for pr in fruit_prices.values(): 13. prints the value of cherry_price
sum = sum + pr 14. prints the value of is_date_available
12. is_date_available = "date" in fruit_prices 15. prints the total of the prices of all the fruits
13. print(cherry_price) OUTPUT:
14. print(is_date_available) Line 1: 80.0
15. print(sum)
Line 2: Cherry price: Not available
Line 3: dict_keys([‘apple’, ‘banana’,’mango’, ‘grape’])
Line 4: 4
Line 5: Not available
Line 6: False
Line 7: 310.0
Line 8:

You might also like