11/13 How do I check the code works for any food?


#1

#2

for a function to execute, you need to call it. Add several function calls with different arguments to see how the food parameter is working


#3

Apologies. I know i need to do that but I dont understand how to make a function call and I cant see any examples


#4

compute_bill(‘banana’)

???


#5

I guess what I am missing is the understanding the line between…

def compute_bill(food):
total = 0
for item in food:
if stock[item] > 0:
total += prices[item]
stock[item] -= 1
return total

and the shopping list?


#6

Functions have been taught? You can always check documentation or earlier lessons if you need a syntax refresher.

compute_bill(‘banana’) is indeed a function call, but 'banana' is a string. The function call should get a list as argument, for example shopping_list

a parameter (food in your case) gets its value from the argument at function call


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.