FOODS = {'Beef', 'Chicken'}
# The calories for each food item (a dictionary, where
# key = food name (string) and value = calories (int)
CALORIES = \
{ 'Beef' : 200, \
'Chicken' : 140, \
}
class Food():
__slots__ = (
'name', # string name
'cal' # Calories
)
def mkFood( name ):
result = Food()
result.name = name
result.cal = [calories for calories in CALORIES.values()]
return result
这是计算卡路里目标项目价值的正确方法吗?就像得到 200、140 一样。
试图获得卡路里的价值。就这些。
result.cal = calorie in dict(CALORIES[1])