How do I print out the total on lesson 13. lets check out


#1

How do I print out the total on lesson 13. lets check out

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

stock = {
    "banana": 6,
    "apple": 0,
    "orange": 32,
    "pear": 15
}
    
prices = {
    "banana": 4,
    "apple": 2,
    "orange": 1.5,
    "pear": 3
}

# 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

print compute_bill(food)

#2

@maxwellchinto,
As indentation is very important in Python coding
please
re-edit your Post

  • leave one blank-line above of your code
  • select your code in the Post
  • then =click= on the </>-symbol-of-this-editor

Your code will then be in a pre-code state
and you will be able to make/present the proper indentations.

or even better use
= http://discuss.codecademy.com/t/using-backticks-to-format-your-code/3697
[extra's]
https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet


#3

Without knowing the error, my best guess would be to edit this line:

print compute_bill(food)

to

print compute_bill(shopping_list)

P.S. Please always format your post (as @leonhard_wettengmx_n had noted) Thanks!


#5