Stocking Out - What is wrong?


#1

def compute_bill(shopping_list ):
total = 0
for items in shopping_list:
if stock > 0:
total += prices[[items]
stock[items] -= stock[items]
return total

I don't get it. Thanks for any hints !


#2

here:

stock[items] -= stock[items]

the user just bought one item, so you need to reduce the item of this stock by 1


#3

so

stock[items] = stock[[items] - 1
?


#4

yes, but i spotted another mistake here:

total += prices[[items]

look closely at (the number of ) square brackets you use there


#5

oh i see. well thats what i got so far

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

but it didnt work ( return total
^
SyntaxError: invalid syntax)


#6

this ilne:

total += prices[[items]

you really need to be more careful with your square brackets


#7

oh awkward. thank you.


#8

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