10. A day at the supermarket


#1



https://www.codecademy.com/courses/python-beginner-en-IZ9Ra/1/3?curriculum_id=4f89dab3d788890003000096


Preview shows correct result but I'm getting error saying code for orange doesn't look quite right. Can you see a bug ?


prices = {
    "banana": 4,
    "apple": 2,
    "orange": 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]


#2

Your problem is probably here : print "prices: %s" % prices[key] , you should not say prices but price you should pay more attention on the instructions


#3

I know about this and seemed odd to me too but instructions says "prices" not "price" but will correct it maybe it will work after that ....


#4

No,you are wrong.The instructions show you a code like this :

apple
price:
stock:

it says price not prices


#5

Corrected and still getting the same error ...


#6

Hmmm i don't know then , this is mine and it says it's absolutely right.Try to find a difference or something i don't see any problems tho

shopping_list = ["banana", "orange", "apple"]

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

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

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


#7

This is funny even though I corrected the price preview still shows prices lol


#8

LMAO i sent wrong code wait a sec


#9

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]

There you go


#10

Dammit it worked ! I just got rid off that "s" in first price like so print "price: %s" % prices[key]

and passed ..... Once it's okay then it's not ...... grrrrr ..... lol

Thank you bro ..... !


#11

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