Keeping Track of the Produce


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????


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??


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!


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

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


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]



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]


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]


price instead of prices


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.


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


Yeah, it's a bug. stupid.


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


I was quite sure.


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

April 28

Yeah, it's a bug. stupid.


Ok.It's a bug.

But how we go further?


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