Error Message on "apple" only


#1

I was wondering if someone else is getting the same error as I do. It keeps saying :
**"Oops, try again. compute_bill(['apple']_ returned None,
did you remember to return the result?"**


My code looked like this:

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 prices:
        total += prices[item]
    print total


#2

Here:

you want to loop for item in food and not prices.


#3

I've been switching that part up and it still has the same error:

def compute_bill(food):
    total = 0
    for item in food:
        print item
        total += prices[item]
    print total

#4

Okay, return and not print the for loop here:

Please, retain the last code edit.


#5

Lol thanks! This worked


#6

You're welcome.

Have fun coding! :slight_smile:

[Yeah! You should learn to return your loop output before considering print.]


#7

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