Keeping Track of the Produce


#1

prices ={

"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}

stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}

for i in prices:
if i == "apple":

I have an error called

Oops, try again.
Check what your code prints for orange. It doesn't look quite right!

Please help


#2

You do not need an if condition, nor do you need to print i.

for i in prices:
    if i == "apple":

You only need to print the prices and stocks. :slight_smile:


#3

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

Look the result !! it's not correct


#4

Are you print your prices and stock's like this?

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

#5

for i in prices:
print i
print "prices:%s" % prices[i]
print "stock:%s" % stock[i]

Like this but the same


#6

Hre, there is no space between prices: and the placeholder %s there needs to be a space,


#7

Nothing changed Mr bandit


#8

You have to get rid of the s after prices in print. It should look like this: "price: %s" % prices[i]"


#9

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

it look the same nothing changed, look this code above


#10

You have a quotation mark on this line that shouldn't be there,

after [i]


#11

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]

I remove that quotation mark but nothing changed

Please help


#12

Why did you name it Once and Twice? It should be prices: and stock:


#13

Thank you for all help me here

I get the answer

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]

Completely correct


#14

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