Something of Value:


#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]
    
total = 0
for food in prices:
    print total += prices[food] * stock[food]
    
print total

#2

you have a question or error message?


#3

yes stetim94 i have syntax error

File "python", line 21
print total += prices[food] * stock[food]
^
SyntaxError: invalid syntax


#4

you can't increase a variable and print it at same time.


#5

so what can i do to multiply the number in prices by the number in stock. Print that value into the console and then add it to total.


#6

no:

  1. Finally, outside your loop, print total

nothing about printing inside the loop


#7

But, i want to add the total number from the product to the total variable. what approach should i use plz.?


#8

you should, but you can't add and print at the same time.

remove print from this line:

    print total += prices[food] * stock[food]

#9

`
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 food in prices:
print prices[food] * stock[food]

print total `


#10

this is my last update of my code


#11

you where updating total correctly, all you had to do was remove print


#12

but still didn't get the correct result!!!


#13

can i see an updated version of your code?


#14

this is the updated version of my code

    "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 food in prices:
    print prices[food] * stock[food]
    
print total

#15

no, no, no. You want to add prices[food] * stock[food] to total. Then outside the loop, print total, no print inside the loop


#16

THANK YOU VERY MUCH, DID IT

    "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 food in prices:
    total += prices[food] * stock[food]
    
print total

#17