Compute bill


#1

Problem.

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

Error code:
compute_bill(['banana', 'apple', 'orange', 'pear']) returned 2 instead of 10.5

Solution:
def get_help(user):
for user in user_list:
print "Help!"
if user == working_solution:
print "Thanks!"
elif user == different_error_code:
print different_error_code
else:
print "Sorry, that didn't work"


ERROR IN - A Day at the Supermarket Making a Purchase
Making a purchase
#2

Get the joke in the "Request" section?

P.S. This is valid trouble.


#3

I would recommend making a list called shopping_list, filling it with items, then using dictionaries and a function called compute_bill at the end, which has loop which returns total.

P.S. if that was what you are asking for.


#4

In the for loop you use key which is not defined, it should be item (from for item in food).

And please note that return statement must be placed outside the for loop:

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

#5

I`m getting error.....Help me..=D


#6

Use ' food ' instead of ' "apple" '


#7

For each suggestion:
1. "Sorry, that didn't work"
2. Your code did not run to end. Check the console window for errors.
Console window: File "python", line 19
SyntaxError: 'return' outside function


#8

I miscalculated the tabbing for the return function.
Updated error code:
compute_bill(['apple']) resulted in a TypeError: unhashable type: 'list'


#9

I think I did that. Example, please.


#10

a list looks like this:

code = [coe, co, code]

a dictionary looks like this:

dictionary = {
"dictionary":10
"words":9
}

Is that what you are asking for?


#11

Ok. I already did that. Could you please explain what the error code in my above post (my second most recent post) means?


#12

May I see your code????


#13

Look at the second post


#14

I mean updated code please


#15

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

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


#16

compute_bill(['apple']) resulted in a TypeError: unhashable type: 'list'


#17

Try putting your function after all of your lists and dictionaries


#18

"Sorry, that didn't work."


#19

Try replacing item in loop with key


#20

Sorry, that didn't work.
Anything else?