# Trying out lpSum

In this exercise you are making two types (premium and budget) of ice cream, using heavy cream, whole milk, and sugar. One version is a premium version containing more cream than your budget version. You are looking to find the mixture of ingredients that minimizes the total costs of ingredients.

Ingredient | $/cup |
---|---|

Cream | $1.5 |

Milk | $0.125 |

Sugar | $0.10 |

Two Python lists called `prod_type`

and `ingredient`

have been created for you, along with a dictionary `var_dict`

containing the decision variables of the model. You can explore them in the console.

This is a part of the course

## “Supply Chain Analytics in Python”

### Exercise instructions

- Define the objective function using
`lpSum()`

with list comprehension and the information in the table above. Iterate over the product types and multiply the dictionary variable by the correct ingredient cost.

### Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

```
# Define Objective Function
model += lpSum([1.5 * var_dict[(i, 'cream')]
+ ____ * var_dict[(i, 'milk')]
+ ____ * var_dict[(i, ____)]
# Iterate over product types
for i in ____])
```

This exercise is part of the course

## Supply Chain Analytics in Python

Leverage the power of Python and PuLP to optimize supply chains.

Linear Programming (LP) is a key technique for Supply Chain Optimization. The PuLP framework is an easy to use tool for working with LP problems and allows the programmer to focus on modeling. In this chapter we learn the basics of LP problems and start to learn how to use the PuLP framework to solve them.

Exercise 1: Basics of optimizationExercise 2: To LP, or to not IP?Exercise 3: Choosing exercise routineExercise 4: Basics of PuLP modelingExercise 5: Getting started with LpProblem()Exercise 6: Simple resource scheduling exerciseExercise 7: Using lpSumExercise 8: Trying out lpSumExercise 9: Logistics planning problem### What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.