# Compute_bill[apple] returns 10.5 instead of 2

#1

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]

This my code.But I still get the same error that compute_bill[apple] returns 10.5 instead of 2.Please do help me

11/13. Making a Purchase
#2

Try iterating the list you passed in as the argument--food.

#3

I get the exact same result

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

I followed the model given in the lesson for calculating sum, so I'm lost at this point

#4

Spoilers below. But this is how I got it to work. Food is going to be a list of products so you need to add the price for each product.

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

#5

Hello, I got the same error and take the @jgsimmon advice, the code:

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

print compute_bill(stock) #it could be any dir

#6

Hello,

I am using the same code as suggested in this thread but I keep getting an error.

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

the error i get is “Oops, try again. compute_bill([‘banana’, ‘apple’, ‘orange’, ‘pear’]) returned 4 instead of 10.5”

#7

Mine is just giving the wrong numbers.

shopping_list = [“banana”, “apple”, “orange”]

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

It finalizes with an error of: “compute_bill([‘apple’]) returned 1.5 instead of 2”

So it’s giving me the price of oranges instead of the apple

#8

Make sure to backspace the return code by 2 spaces, then you should get 10.5

#9

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