IndentationError: unexpected indent

On the number guess dice project, it says, “IndentationError: unexpected indent” when I run my code. I would assume I had something wrong however I’ve watched the walkthrough and typed in exactly what the developer did with the same indentation. This happened on a previous project as well. The link is https://www.codecademy.com/courses/learn-python/projects/number-guess

Hello, @dev3074334203. Welcome to the forum. Could you paste the code that raised the error? Make sure to use the </> button in the menu bar, or none of your code will retain its original indentation. Click on the </> then paste your code in the space indicated.

5 Likes

I deleted that section and retyped it and that worked for some reason. I don’t think i changed anything.

Since Python uses indentation levels to delineate code blocks, you likely had a line indented that should not have been. Even a single line indented a single space that didn’t match the indentation level of the rest of the code in the block would throw the error. Even this line by itself throws the error:

 print("hello world") #indented a single space
#throws: IndentationError: unexpected indent (<string>, line 1)
3 Likes