Something of value


#1

In this program I am getting the o/p as the total is not correct can somebobdy help me to find out my error

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

#2

here:

x=prices[key]*stock[key]

why do you use key? That you used in the first for loop as iterator, not in the second loop so its not the right variable to use


#3

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