Error in different codes?


#1



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


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


its the same results just different code


*(apparently it does not accept this code)*
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:",prices[x]
    print "stock:",stock[x]

*(this was the code that it accepts but its the same results)*
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: %s" % prices[x]
    print "stock: %s" % stock[x]


#2

except the validation of the exercise uses function, and , is an argument separator, so in case of your first code it only sees:

for x in prices:
    print x
    print "price:"
    print "stock:"

#3

im still kinda confuse wat u meant sorry


#4

the exercise needs to verify your code is correct, to achieve this, functions are used

the , is tripping up the function because , separates function arguments (print "price:",prices[x] is an argument for the function which validate exercise code, but the , separates the arguments, something the validating functions don't expect.

If you don't understand this, move on, its not important, just know the exercise validation can't handle what you did


#5

ohhhhh in a sense it needs one arguements instead of 2 due to (,). thanks for the help


#6

yes, it expects one argument, but because you used a different approach, it got two arguments (due to ,), which will cause problems in the validition


#7