Teach Yourself Python #48 "For Loops and Lists"

Hey everybody. I’m working through “Teach Yourself Python”
http://www.codecademy.com/courses/python-beginner-en-fymF4

Im stuck on #48 (or Unit 5, Exercise 4)
https://www.codecademy.com/en/courses/python-beginner-en-fymF4/5/4

Instructions
For each item of fruit, print out “In stock:” and then the name of the fruit.

(my code)

fruit = ['apple', 'pear', 'mango', 'lime']

for i in fruit:
    print "In stock:" + i

Keeps throwing up an error.
any tips? any suggestions?

Thanks everyone. DB

fruit = ['apple', 'pear', 'mango', 'lime']

for i in fruit:
    print "In stock:" + i

I did use proper indentions in my code.

“Opps, try again” is the Error message.
code prints to the screen properly.

Only by reading the submission test could I figure out that you’ll need to print it this way:

print "In stock:", i

Because it’s looking for the fruits to be printed separately instead of looking at the output as a whole

3 Likes

Thank you so much.
Perhaps I would have stumbled upon the use of the comma, but it might have taken a few days.

@ionatan !! Thank you

This Python course has been fun.
it trucks along smoothly.
that was one of the first exercises to give me a road block

DB :four_leaf_clover: :globe_with_meridians: :computer: :smiley:

1 Like