HELP: Keeping Track of the Produce


#1

Hello! I need help! In this exercise the result of my code is as follows:

apple
prices: 2
stock: 0
None

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

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

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

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

Can you help me please? thank you!


#2

They said to print "orange" and not apple. Currently, you're printing "apple" and it's price/stock. Change your key to "orange".


#3

Thanks for your reply!

I already did what you suggested to me but the problem continues and the error remains the same!

However I read with more attention and the purpose of the exercise is to list all products according to the rule given in the example.

Actually this is my output from my code:

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

At the moment my code is as follows:

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 "prices: %s" % prices[key]
    print "stock: %s" % stock[key]

unfortunately the error still the same:

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


#4

this is one of those lessons that it checks for exact output;
prices: should be price:
:slight_smile: , hope this helps


#5

Way to go!! :sunglasses:

thank you so much @kyleaw!


#6

I'm glad you fixed it but alas, what I meant by changing "apple" to "orange" is this:

# This is your code you provided above
prices = {
    "banana": 4,
    "apple": 2,
    "orange": 1.5,
    "pear": 3
}

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

for key in prices:
    key = "apple" # <-- Here, change this to key = "orange"
print key     
print "prices: %s" % prices[key]
print "stock: %s" % stock[key]

And as @kyleaw said prices should be price.

Anyways, I'm happy you passed this lesson! Happy coding.


#7

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