Total won't print


#1

while working on this lesson: https://www.codecademy.com/courses/learn-python/lessons/a-day-at-the-supermarket/exercises/making-a-purchase?action=resume_content_item

I encountered an issue where, at first, my print total was I think in the for loop which caused it to be printed a bunch (I also had print prices[item] so I could see if I was messing up), so in an effort to fix that, I moved the print total to right above the return total. However, nothing is printing now, and when I deleted the whole function codeacadamy still had the Next Up button and I was worried my code was wrong but I just couldn’t tell. I tried resetting it and had the same problem. Here is a few variations on the code I tried (first one is the whole code and the others are just variations on the same function):

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.0
–for item in food:
----if stock[item] > 0:
------total += prices[item]
------stock[item] -= 1
–print total
–return total

— try 2

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

— try 3

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


#2

Imagine if + printed things out each time you used it. Not very useful, rather annoying, it’s not supposed to do that.

What you’d normally do instead is to carry out the addition and print the result: print 3 + 5

Oh and, even if + did do printing, it would never do so by itself, it would have to get used first or that code would never run, regardless of how many print statements were in it. For example, an empty program won’t print anything even though + exists in it. But if you used it, and it had prints in it, then you would get output. Perhaps you never use your function, that would explain why nothing gets printed.

This program has no output:

def f():
    print('Hello, World!')

However, this one does:

def f():
    print('Hello, World!')

f()