Stocking out


#1

what is wrong ?


#2

I figured it out...


#3

what was it? i cant do it either.


#4

HI just after your total = total... you should add under it

stock[item]  = stock[item] - 1

Or 

stock[item]  -= 1

#5

thank you @wizmarco !


#6

thanks @wizmarco i appreciate


#7

shopping_list = ["banana", "orange", "apple"]

stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}

prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}

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

here is my code; it's not working - can someone tell me why?


#8

nevermind - i accidentally put greater than or equal to


#9

shopping_list = ["banana","orange" ,"apple"]

stock = {
"orange": 32,
"pear": 15,
"banana": 6,
"apple": 0
}

prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}

Write your code below!

def compute_bill(food):
total = 0
for x in food:
if (stock[x] > 0):
#print "%s has stock >0" %x
total += prices[x]
stock[x] -= 1

return total

print compute_bill(shopping_list)
for x in stock:
print "%s:%d" %(x,stock[x])

Ouput


5.5
orange:31
pear:15
banana:5
apple:0
None

My code it is reducing the stock once Purchased . I am getting the erorr message "Oops, try again.
stock doesn't look quite right! Make sure to not call compute_bill
since it changes the stock! It should contain: {'orange': 32, 'pear':
15, 'banana': 6, 'apple': 0}
"

Please let me know ,what is the erros msg


#10

Hi Everyone,
Can you help me with this?


#11

nevermind. i just moved return few spaces back (should be aligned to for)


#12

Write your code below!

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

print stock

"""This works! Have a nice day."""


#13

It wont go if the indenting is wrong!