PYTHON CORE · LESSON 40
Outcome draft
Count the purchases. · about 18 minutes
Learning with progressRead the summary for free. To save the work, log in to the account.
Type the code yourself
Reprint the little project. Keep an eye out for nested indentations.
def total(prices):
result = 0
for price in prices:
result = result + price
return result
cart = [2, 3]
print(total(cart))Open the editor for class workSolve it yourself
Create the function total(Zprices): start with result = 0, loop for price in prices add the prices and returns result. Create cart = [2, 3, 4], call total (cart) and output the answer.
The answer is hidden. Use similar examples from the lesson notes.
Opening up your homework