Stocking out


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

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

This is the error code I get. PLease help me understand
File “python”, line 23
stock[key] -= 1
^
IndentationError: unindent does not match any outer indentation level

<In what way does your code behave incorrectly? Include ALL error messages.>

<What do you expect to happen instead?>

```python

Replace this line with your code.

<do not remove the three backticks above>

#2

look at the code:

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

the stock[key] -= 1 doesn’t match the indent of: function, for loop, if clause)

which indent level (number of spaces or tabs) should it match?


#3

total += prices[key]


#4

very good :slight_smile: but as we can see;

    	total += prices[key]
      stock[key] -= 1

they currently do not match, but now you understand what is wrong, you should be able to fix it :slight_smile:


#5

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