Advertisement
yragi_san

Fruit Basket

Oct 5th, 2020
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. # You would like to count the number of fruits in your basket.
  2. # In order to do this, you have the following dictionary and list of
  3. # fruits. Use the dictionary and list to count the total number
  4. # of fruits and not_fruits.
  5.  
  6. fruit_count, not_fruit_count = 0, 0
  7. basket_items = {'apples': 4, 'oranges': 19, 'kites': 3, 'sandwiches': 8}
  8. fruits = ['apples', 'oranges', 'pears', 'peaches', 'grapes', 'bananas']
  9.  
  10. #Iterate through the dictionary
  11. for key,values in basket_items.items():
  12. print(key,values)
  13. if key in fruits:
  14. fruit_count += values
  15. else:
  16. not_fruit_count += values
  17. #if the key is in the list of fruits, add to fruit_count.
  18.  
  19. #if the key is not in the list, then add to the not_fruit_count
  20.  
  21.  
  22. print(fruit_count, not_fruit_count)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement