Welcome to Westonci.ca, the place where your questions find answers from a community of knowledgeable experts. Explore thousands of questions and answers from a knowledgeable community of experts ready to help you find solutions. Discover in-depth answers to your questions from a wide network of professionals on our user-friendly Q&A platform.

In this problem, you should write one function named count_calories. This function should have one parameter, which will be a dictionary of food items. The keys will ne the name of a food item (such as 'granola' or 'steak'), and the value associated with each food will be the integer calorie amount for that food. The function should iterate through all of the foods and sum up the total calories, and then return that number. For example:
count_calories({'chocolate':200, 'milk':120, 'steak':250}) should return 570.
count_calories({'carrot':5, 'apple':50}) should return 55.
Make sure to include only the one function in your file.


Sagot :

Answer:

The function is as follows:

def count_calories(dictt):

   total = 0

   for keys, values in dictt.items():

       total+=values

   

   return total

Explanation:

This defines the function

def count_calories(dictt):

This initializes total to 0

   total = 0

This iterates through the dictionary

   for keys, values in dictt.items():

This adds the dictionary

       total+=values

This returns the calculated total    

   return total