Keeping Track of produce


#1



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 don't know what is wrong with it!


#2

@magykal

Sorry for being repetitive but what's the link of your exercise right now?


#3

https://www.codecademy.com/courses/python-beginner-en-IZ9Ra/1/4?curriculum_id=4f89dab3d788890003000096# the one I am doing right now


#4

@magykal

I think Price and Stock should not be capitalized.


#5

we have same code, why your working well?


#6

"Price: "should be "price: "
the same to stock


#7

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

I have similar code and get this error:

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

Orange is fine. Dunno what is wrong here... :confused:

EDIT: It worked now. Still don't know what was the problem. :unamused: I just copied and pasted code from the next step.


#8

**

**I was having the same issue, removed the "s" from all the prices, and it corrected it

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


#9

Since this is the tutorial. The print "whatever string you want" is case sensitive as well as it needs to be show exactly as what the tutorial shows. So if you're missing ":" when you print your string, it won't let you proceed, even though your code is correct and you understand the concept.


#10

so what should I do now
or u post ur code fr us to see


#11

print "Price: %s" % price[key]
print "Stock: %s" % stock[key]

Price: and Stock: P and S needed to be capitalized


#12

This was my code. It worked, although it does NOT print correctly.

prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear":3
}
stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15,
}

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

For whatever reason taking the s out of the print "prices %s" %prices[key]

so that it became

print "price %s" %prices[key]

Made the program accept it as correct. No idea why, and no idea why it doesn't do what it's supposed to though. Kind of a bummer.


#13

Hello guys,

capitalization seems to be the error or confusion. (price and stock) , without any capital


#14

This code doesn't work, can someone help me
prices = {
"banana": 4 ,
"apple": 2,
"orange": 1.5,
"pear": 3
}

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

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


#15

Print in the correct order specified in instructions with key first, then price and then, stock.
Example:

apple
price: 2
stock: 0

Note: this example was pulled right from the instructions

Also please have everything in lower-case as discussed in this thread. And make sure to spell price correctly.