A1W2_excercise 4

I can’t understand what’s wrong with both lines.
an error message appear “indentation error”
Any help…

Hi @maissa1,
To provide more specific assistance with your Python code, it would be helpful to know the details of the course and the particular lab exercise you’re working on. This will help the mentors to pinpoint the issue and guide you more effectively.

Python is sensitive to indentation as it uses spaces or tabs to structure code. An “indentation error” typically indicates that the blocks of code are not aligned correctly according to Python’s syntax rules.

Yes, as Lukman says, indentation is a fundamental part of the syntax in python. You can’t just “slide things around” to make them look good to your sense of aesthetics: you have to understand and follow the rules. Just as one example, the “body” of a function must be indented one more level than the “def” statement that defines the function. If you are new to python, please be aware that the courses here assume you already know python. If that’s not the case, you might want to take an “intro to python” course before continuing. If you are very experienced in other languages like JavaScript, C#, C++ or Java, then you probably don’t need to take a full python course, but you should definitely spend some time reading the tutorials on the python.org website. There are some unusual things about python and the “indentation as syntax” is high on that list. :nerd_face:

One other subtlety here is that I believe that the notebook environment is a bit more forgiving than the grader. Just to be on the safe side, it’s better to just use tabs for the indentation, as opposed to mixing spaces and tabs.

1 Like

I am level zero in Python, I will take a look at the link provided…
Wish me luck
Thank you