Keeping Track of the Produce


#1

Here is my code:

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

I'm getting the following error message:
Oops, try again. Check what your code prints for orange. It doesn't look quite right!

What am I doing wrong????


#2

I took out "s" from prices and it worked. Here is my code that worked:

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

Is there a specific reason why this worked and not my previous code??


#3

Had the same issue. My code was:

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

for fruit in prices:
print fruit
print "Price: %s" % prices[fruit]
print "Stock: %s" % stock[fruit]

worked when I changes cap P and cap S to lowercase... don't know why... a bug maybe?

Anyways, thanks for your hint!


#4

I used the below.
the idea is to calculate the total cost of the products ( 4 + 2 + 1.5) = 7.5

def compute_bill(food):
total = 0
for qty in food:
total = total + prices[qty]
return total

print compute_bill(shopping_list)


Compute_bill(['apple']) returned 63.5 instead of 2
Making a purchase
#5

I'm pretty sure that it is case-sensitive.


#6

Thank you for your answer.

It does not make sense though to be case sensitive, because it is in a
"string" that I used capitals.

print "Price: %s" % prices[fruit]
print "Stock: %s" % stock[fruit]

Cheers!


#7

I think it is all about the letter that comes after % sign, when I kept changing them until g and it worked. The code is here:
prices = {'banana': 4, 'apple':2, 'orange': 1.5, 'pear': 3}
stock = {'banana': 6, 'apple': 0, 'orange': 32, 'pear': 15}

for x in prices:
print x
print "price: %g" % prices[x]
print "stock: %g" % stock[x]


#8

Well here's mine and it worked, although I'm kind of suspicious in the for loop part because I used an operator.

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

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

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

#9

price instead of prices


#10

Well this code worked because we had to print "price" instead of "prices". I did the same mistake and saw your question and rectified my mistake.


#11

Look: your output will be priceS: ... instead of price: ... That is the only reason.
The letter "S" is the mistake.


#12

Yeah, it's a bug. stupid.


#13

I'm having the same issue. Why is the string case-sensitive??


#14

I was quite sure.

Tnx!

Στις 28 Απρ 2017 12:36 ΜΜ, ο χρήστης "Robodog23" <
codecademy@discoursemail.com> έγραψε:

robodog23 https://discuss.codecademy.com/users/robodog23
April 28

Yeah, it's a bug. stupid.


#15

Ok.It's a bug.

But how we go further?


#16

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