8/13 help


#1

my code is as follows:

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

but the error says:

Traceback (most recent call last):
File "python", line 25, in
TypeError: 'int' object is not iterable


#2

Can you explain why you added these lines?

You actually dont need them!

also here..

for key in stock:
    print "stock: %s" % stock[key]
    print "price: %s" % prices[key]

Indent it like I did.
also make sure that you print fruit's name(key) before these two lines inside of for loop.


#3

i added the lines because it was the only way i could think of doing it at the time and thanks ill do that


#4

so i did that but now it says this:

Traceback (most recent call last):
File "python", line 26, in
TypeError: 'int' object has no attribute 'getitem'


#5

can you post your code?


#6

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