Stocking out


#1

x = prices[x]

why that code??? y not just connect it to

total

right away?? btw I did that and it came out

{Oops, try again. calling compute_bill with a list containing 1 apple, 1 pear and 1 banana caused the following error: unsupported operand type(s) for -: 'str' and 'int'}

for xyz in food:
        if stock[xyz] > 0:
            stock[xyz] = xyz - 1
            total += prices[xyz]
        else:
            print 'out of stock'
    return total

so I aint fresh


Stocking out problem
#2

That would be more efficient. But its valid to first store it in a variable, and then add it to total.

Your problem is here:

stock[xyz] = xyz - 1

xyz is a product (apple for example), which is a string:

"apple" - 1

that doesn't work. You should use xyz as key for your stock dictionary, and reduce that by one


#3

hey there before I tried changing it the way u told me, I tried submitting it the way it was and this error message came out:

Oops, try again. calling compute_bill with a list containing 1 apple, 1 pear and 1 banana resulted in 0 instead of the correct 7


#4

Can i see your full code?


#6

here:

stock[xyz] = xyz - 1

you get the stock value, which you want to re-assign very good. But then you want to reduce the stock value (stock[xyz]) by one, not the product (xyz)


#8

But then you have much closer at the solution then you currently show. Are you just trying?

Then then final piece of the puzzle is to place return outside the loop so the whole can run (if a return keyword in the loop is reached, the loop breaks)


#11

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