Something of Value


The Total is coming incorrect, I do not know where the error is my code. Pls help

Replace this line with your code. 
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]
for key in prices:
    price[key]*stock[key]+ total
print total


Hello :slight_smile:

There are two problems in your code, both related to this line:

price[key]*stock[key]+ total
  1. It should be prices, not price;
  2. Calculations are correct, but you have to save somewhere the results! You want to accumulate prices of each product in the total variable, right?

total = prices[key]*stock[key]+ total


Thanks a lot that fixed it..


You're very welcome :slight_smile:


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