I guess i wrong code or what


#1

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

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

error..///
It looks like your code did not print the correct total....

little stucked help guys


#2

Guessing you are on excersize 9/13 so here is how to do that one
so you have the dictionaries correct but the code is a little off. for the first print function you should have.

for fruit in prices:
    print fruit
    print "price: %s" % prices[fruit]
    print "stock: %s" % stock[fruit]

the 'fruit' can be anything you want so for your code you would do

for item in prices:
    print item
    print "price: %s" % prices[item]
    print "stock: %s" % stock[item]

Also i would crate a variable to store the total of the prices and the stocked items

for price in prices:
    both = prices[price] * stock[price]
    print both
    total = total + both

for your loop you make it print what its supposed to and than prints 0 because total = 0 so that is why you get that error
I created a variable called both so i can just take the variable and add it to the total


#3

its not working bro more help


#4

double check your spacing is all i can think of atm

is this for excersize 4/13 or 5/13


#5

9/13

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

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

i tried this also