11. Making a Purchase


#1

https://www.codecademy.com/en/courses/python-beginner-en-IZ9Ra/2/2?curriculum_id=4f89dab3d788890003000096

Hi! So I can't really see what I'm doing wrong… I keep getting the error message -> "Oops, try again. compute_bill(['apple']) returned 7.5 instead of 2" ….. Please help.

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 foods in shopping_list:
        total += prices[foods]
    return total

#2

Should be food, your function's parameter instead of shopping_list in your for loop statement.


#3

Hi this line

for foods in shopping_list:

it should for foods in food(instaed of shopping_list)


#4

Thank you! :sweat_smile:


#5

Thanks! I din't know that :sweat_smile:


#6

What do I do if it says return is an outside function.


#7

Hi you can post your code or create a new topic


#8

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 foods in food:
total += prices[foods]
return total


#9

HI does your function indent like that ?

def compute_bill(food):
    total = 0
    for foods in food:
        total += prices[foods]
    return total

#10

Thanks for the help. .


#11

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