# A day at the supermarket

#1

A day at the supermarket making a purchase

"Oops, try again. compute_bill(['apple']) resulted in a TypeError: unsupported operand type(s) for +: 'int' and 'str'"

all the items in the food list to add into the 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
}

def compute_bill(food) :
total = 0
for item in food:
total = total + item

#2

here..
`total = total + item`

`total` is a number.

`item` is a string (for example "apple","pear" etc)

hint**
But you have to add price of these fruits?
You can use `prices` dictionary?

#3

yeah how do i do that i stil dont understand very well?

#4

lets revise how to loop over a dictionary..

if there is a dictionary called alphabets..

`alphabets = {"a": 1, "b" : 2, "c": 3, "d": 4}`

I want to add values of "a","b","c","d" together.

values 1,2,3,4 .

now..

``````total =0
for key in alphabets:
total =  total + alphabets[key]``````

what you think what value `total` will have now?

#5

yeah that didn't work, total would be 10

def compute_bill(food) :
total = 0
for items in food:
total = total + food(items)

#6

the indents are in there dont worry

#7

`food` is a list not a dictionary but `prices` is a dictionary with price list of each fruits ?

#8

tell me whats wrong with 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 key in prices:

``````    total = total + prices [key]

#9

`for key in prices:`

#10

done it no thanks to you

#11

how you do it, i'm serious

#12

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