Identation Error: Unident does not match any outer identation level

Screen Link: https://app.dataquest.io/m/312/lists-and-for-loops/9/for-loops

My Code:

rating_sum = 0
for row in app_data_set:
    rating = row [-1]
    rating_sum = rating_sum + rating
    print(rating_sum)

What I expected to happen: I expect the execution of the code

What actually happened:
Error

IdentationError: Unindent does not match any outer identation level

I followed all instructions yet I am still getting same error

Did you type out that code yourself or did you copy and paste it from somewhere else?

Because the issue that you seem to be facing is most likely because of copying and pasting code from somewhere else.

In your for loop, as you can see, the code lines (10 - 12) are indented. Those indentations can either be added by pressing the space bar four times, our by using the Tab key.

Unfortunately, depending on the interface you are using, those 4 space bar presses, and the ` Tab key, are not equivalent in Python. And that can lead to the kind of error you got. This is common when you copy-paste code from somewhere else.

So, I would recommend that you

  • remove that code,
  • type out the code yourself,
  • make sure you either indent using either just the space bar or just the Tab key,

and try again. Because I just tried the code you share above, and didn’t get the same error.

I would also recommend removing the space between row and [-1]

1 Like

Thanks the_doctor,
Yes, i typed the code myself, but the identation at line (10-12) came by itself when I clicked on enter key after line 9.
I have carefully deleted the identation space in line (10-12) and I put the space myself by clicking the space-key 4 times but I still got another error which is syntax error.

Just noticed that you are working on your phone.

I can’t be sure, but since your code works for me on the desktop website, it seems that your phone keyboard might be causing some issues when you type things out.

I would recommend that you first work through this on your laptop/desktop. Because the code you shared above seems to run fine.

You could also try to make sure your keyboard’s language is set to en-US or maybe even en-UK just in case.

Sorry, I don’t think I can help more than this given your code seems to run fine when I try it out.

2 Likes

Hi @sahil,
I need your attention here, I followed all instructions when writing my code yet I am getting syntax error. Pls kindly help me out

Hi @sadorwilliamz3 ,

While the platform is completely functional on a device like a smartphone, the web app was designed, first and foremost, with the desktop experience in mind, in order to simulate a real-world DA/DS workflow. This means that there are things that are less than optimal on a smartphone, like the size of the coding window, and having to use the virtual keyboard to code.

Mobile/Tablet keyboards use curly quotes instead of straight quotes. This image shows the difference.

The python interpreter doesn’t accept curved quotes for representing string values. So you may get SyntaxError: invalid character in identifier when using a mobile device.

Even though your code may appear to be exact as the solution, there might be an invisible character like zero-width space which could be the cause of this problem. This typically happens when we access the platform using mobile.

I hope this helps! I recommend you to use a desktop/laptop to use our platform.

If you don’t have access to a desktop/laptop, then here is a way to solve this issue (not guaranteed):

Notice the ^ character in your error. This indicates that there is an invalid character (Probably zero-width space) somewhere around the rating variable. Place your text cursor on the left side of r. Hit backspace until the text cursor reaches the : character in the previous line. Now hit enter and run your code.

Most probably the issue will be fixed.

Best,
Sahil

2 Likes

@Sahil, after so much trial and error, the code finally run

1 Like

Hi @sahil,
I need ur attention here,am also having the same issue with list and loop aspect
screen link : https://app.dataquest.io/m/312/lists-and-for-loops/9/for-loops
My code: ​

7

app_data_set = [row_1, row_2, row_3, row_4, row_5]

8

rating_sum = 0

9

for row in app_data_set:

10

rating = row[-1]

11

rating = rating_sum + rating

12

print(rating_sum)

13

14

avg_rating = rating_sum /len(app_data_set)
I also followed all the instructions given but still getting error

File “”, line 11
rating = rating_sum + rating
^
SyntaxError: invalid character in identifier

Hi @bauzy2357,

If you are learning from a mobile device then this can only be resolved using trial and error. Please refer to this post:

Specifically, this part:

Best,
Sahil