Good! Now you’re going to need to know how much you’re paying for all of the items on your grocery list.
def sum(numbers): total = 0 for number in numbers: total += number return total n = [1, 2, 5, 10, 13] print sum(n)
sumwith a parameter
totalwhich we will use as our running sum.
n, a list of numbers.
sum(numbers)function with the variable
nand print the result.
Define a function
compute_bill that takes one argument
food as input.
In the function, create a variable
total with an initial value of zero.
For each item in the
food list, add the price of that item to
Ignore whether or not the item you’re billing for is in stock.Note that your function should work for any food list.