10 - A Day at the Supermarket


#1


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

I get this error, but my code runs just fine and I think looks right.

This is the error message:
Oops, try again. You should have exactly three print statements! (Make sure there are no occurrences of 'print' in any comment or string!)


I do have three print statments and there are no other ones.


#keeping track of prices
prices = { 
    "banana":4,
    "apple":2,
    "orange":1.5,
    "pear":3
}

#keeping track of stock
stock = {
    "banana":6,
    "apple":0,
    "orange":32,
    "pear":15
}

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


#2

It's dumb, but the error points to an issue with the codecademy interpreter. It says make sure there are no instances of print in any COMMENT or STRING (kind of ridiculous). Remove the word print from printing in your third comment.


#3

Figured it out. It checked for the amount of times "print" was in the text and my comment section #printing inventory. Broke it.


#4

My code prints the exact output format as mentioned in the practice instructions and still getting the below error.

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

orange
price : 1.5
stock : 32

pear
price : 3
stock : 15

banana
price : 4
stock : 6

apple
price : 2
stock : 0

None


#5

I am also having same issues..:frowning:
If anyone has pointed out the mistake ,please inform me.


#6

Can you upload a copy of your code?


#7

I there!!
I also have the same error problem.

This is the code that I used:
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]

This is the error:
Oops, try again. Check what your code prints for orange. It doesn't look quite right

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

Thanks for any help.


#8

I mean it looks right to me. Is your for loop indented?

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

???

if so refresh and try and submit again?


#9

i also hav same problem


#10

I know this code works. The only issue I had was my comment section.
Hope this is of some help


#11

Thanks Arraysurfer,

I found the issue... But I don't understand. Perhaps you can.

First, yes my code was indented, the problem is in the 2 print inside the loop. As you see, you have "price" instead of "prices", which in my opinion it is a bug in the codeacademy script, but maybe I am wrong.

I just replace : print "prices: %s" % prices[key]
for : print "price: %s" % prices[key]

Cheers.


#12

You was right, this work for me, thy vm!


#13

Yeah... it may be trying to read through your code so see if it matches the one they have formatted. If that's the case, even though your script runs just fine, they might fail your code. They might not have come up with a better way to check through the code. :stuck_out_tongue:

I'm no pro at all and I'm just learning but I think that is what's happening.


#14

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

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

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

Write your code below!

def compute_bill(food):
total = 0
for item in food:
total += prices[item]
return total
n = ["banana", "orange", "apple", "pear"]

print compute_bill(n)

this code works for me


#15

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

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

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

Write your code below!

def compute_bill(food):
total = 0
for item in food:
if stock[item] > 0:
total += prices[item]
# print item,total
stock[item] = stock[item] - 1
#print stock[item]
return total
n = ["banana", "orange", "apple", "pear"]

print compute_bill(n)


#16

Hi arraysurfer92650,

I see the trailing comments and answers but I couldn't understand the exact solution for it. Below is my code for the same.

prices = {

"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3

}

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

for item in prices:
print item
print "prices : %s " % prices[item]
print "stock : %s \n" % stock[item]

Output

orange
prices : 1.5
stock : 32

pear
prices : 3
stock : 15

banana
prices : 4
stock : 6

apple
prices : 2
stock : 0

None

Error

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

#17

Also, the issue is not with the price / prices in the print statement. It has the same error for both


#18

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]

For some reason, this code is more favourable than any other one so just use this...coding can be a pain sometimes
Also, make sure you indent the print parts so you don't get an "expected break error" like I did.


#19

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

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

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

Write your code below!

def compute_bill(food):
total=0
for item in food:
if stock[item]>0:
total+=prices[item]
stock[item]=stock[item]-1
return total
Oops, try again. calling compute_bill with a list containing 1 apple, 1 pear and 1 banana resulted in 4 instead of the correct 7
WHAT CAN I DO??!!


#20

I had the same problem as megaace67025, but changing "prices" to "price" helped. But I don't know why :sweat: