+ 2

What's wrong with my code

grocery_list = ["juice", "tomatoes", "potatoes", "bananas"] print("first item", grocery_list[0])

3rd Nov 2016, 8:23 PM
code-junkie
code-junkie - avatar
7 Respostas
+ 6
The print statement in your code IS spaced. Delete that space, and then you will have no problem. I checked I was correct by copying the text into the code editor, then I ran it. It said unexpected indent before print. So I deleted the space, and it ran perfectly without any errors!
18th Dec 2016, 2:44 PM
UnidentifiedProgrammer
UnidentifiedProgrammer - avatar
+ 4
Your print () is indented. In Python everything has to be indented perfectly ;) Just remove your white space before print statement. It is like this: print("first item", grocery_list[0]) This how it should be: print("first item", grocery_list[0])
3rd Nov 2016, 8:37 PM
Mateusz Wiezik
Mateusz Wiezik - avatar
+ 2
@code-junkie in python you use indents (tabs/spaces) instead of { } (java, js, c#) to denote a code block, in your code print() was indented (you had a space in front of it) telling python that it was a code block belonging to something ... that it wasn't there.
3rd Nov 2016, 10:36 PM
Eduard Alexandru
Eduard Alexandru - avatar
+ 1
Yes!
3rd Nov 2016, 8:41 PM
Maycow Carrara
Maycow Carrara - avatar
+ 1
Press backspace before (p)letter in your print statement. You probably pressed space by accident that's all.
3rd Nov 2016, 8:43 PM
Mateusz Wiezik
Mateusz Wiezik - avatar
0
I still don't get it
3rd Nov 2016, 8:41 PM
code-junkie
code-junkie - avatar
0
oh thx
3rd Nov 2016, 8:47 PM
code-junkie
code-junkie - avatar