# Why does it print 4 times?

#1

prices = {
“banana”: 4,
“apple”: 2,
“orange”: 1.5,
“pear”: 3
}

stocks = {
“banana”:6,
“apple”:0,
“orange”:32,
“pear”:15
}
for key in stocks:
print “banana”
print “price: %s” % prices[“banana”]
print “stock: %s” % stocks[“banana”]
print “apple”
print “price: %s” % prices[“apple”]
print “stock: %s” % stocks[“apple”]
print “orange”
print “price: %s” % prices[“orange”]
print “stock: %s” % stocks[“orange”]
print “pear”
print “price: %s” % prices[“pear”]
print “stock: %s” % stocks[“pear”]

why does it print 4 times when i run it? the result is this:

banana
price: 4
stock: 6
apple
price: 2
stock: 0
orange
price: 1.5
stock: 32
pear
price: 3
stock: 15
banana
price: 4
stock: 6
apple
price: 2
stock: 0
orange
price: 1.5
stock: 32
pear
price: 3
stock: 15
banana
price: 4
stock: 6
apple
price: 2
stock: 0
orange
price: 1.5
stock: 32
pear
price: 3
stock: 15
banana
price: 4
stock: 6
apple
price: 2
stock: 0
orange
price: 1.5
stock: 32
pear
price: 3
stock: 15

sorry if this question was really easy, im really noob ;(

#2

the point of the loop is that we can print all the elements from a list without having to repeat ourselves