[solved]


#1

I dont understand what happened:

Oops, try again.
compute_bill(['apple']) resulted in a TypeError: list indices must be integers, not str

This is my code

shopping_list = ["banana", "orange", "apple"]

stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}

prices = {
"banana": 4.0,
"apple": 2.0,
"orange": 1.5,
"pear": 3.0
}

def compute_bill(food):
total=0
for item in food:
print type(food[item])
if food[item]==int(food[item]) or food[item]==float(food[item]):
total += food[item]
return total

print compute_bill(prices)


#2

Solved

def compute_bill(food):
total=0
i=-1
for item in food:
i+=1
print item
#Aqui nace el problema, la siguiente operacion no se realiza en listas
if food[i]==item:
total+=prices[item]
else:
print food[item]
if food[item]==str(food[item]):
total+=0
elif food[item]==int(food[item]) or food[item]==float(food[item]):
total += food[item]
return total

print compute_bill(shopping_list)

print compute_bill(stock)


#4

NOT solved. This code does not work. Also, your first note is unreadable.


#5

Heyoz, Good coders! :slight_smile
There my code is inspired from the over side of the moona!:
Cheers

prices={"banana": 4,"apple": 2,"orange": 1.5,"pear": 3}
stock={"banana": 6,"apple": 0,"orange": 32,"pear": 15}
for key in prices:
if type(prices[key]) is int or type(prices[key] is float):
print key
print "price: %s" % prices[key]
print "stock: %s" % stock[key]


#6

Well after next steps :slight_smile:

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 item in food:
total += prices[item]
return total
print compute_bill(food)