My loop stops at value 0


#1



prices = {
    "banana" : 4,
    "apple"  : 2,
    "orange" : 1.5,
    "pear"   : 3,
}
stock = {
    "banana" : 6,
    "apple"  : 0,
    "orange" : 32,
    "pear"   : 15,
}
total=0
for key in prices:
    print key
    print "price: %s" % prices[key]
    print "stock: %s" % stock[key]
    both= int(prices[key])* int(stock[key])
    print "both: %s" % both
    total= total + both
    print total


output-
orange
price: 1.5
stock: 32
both: 32
32
pear
price: 3
stock: 15
both: 45
77
banana
price: 4
stock: 6
both: 24
101
apple
price: 2
stock: 0
both: 0
101
None


#2

Can you share the link to the lesson?


#3

hi,
i got the answer, that because i declared it as int. when i tried doing it without int i am getting answer.


#4

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