Help 9/13


#1

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

for key in prices:
print key
print "price: %s" % prices[key]
print "stock: %s" % stock[key]
i dont get it


#4

its quite simple all you have to do is times together the stock by price and add it to a variable called total, if your still not sure it should look like this:
total = 0
for x in prices:
total += prices[x] * stock[x]
print total


#5

sry i got a little problem
i try ur way without the line:
"for x in prices:"

which means just:
total = 0
total += prices[x] * stock[x]
print total

and i failed, but i was wondering that i have already the "for x in prices:" above, why do i need to type a new line to make it work ?


#7

I'm having the same problem as you designace. Did it work for you when you added "for x in prices." above?

total = 0
for x in prices:
total += prices[x] * stock[x]
print total

Make sure to indent the total lines. However, I'm still confused why we have to add in for x in prices. Is that the for loop? How do we know when to add in the for loop in code?


#8

Hey,

I have done this and worked like a charm:
total = 0
for key in prices:
cost = prices[key] * stock[key]
total = total + cost
print total

hope this will help


#9

Be careful about Indentation !!!
Here is the solution:


#10

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

for key in prices:
print key
print "price: %s" % prices[key]
print "stock: %s" % stock[key]
total=0
for key in prices:
total += prices[key] * stock[key]
print total


#11

for key in prices:
....print prices[key] * stock[key]
....total = total + prices[key] * stock[key]
print total

did it this way to avoid making another variable