All of my elif statements give syntax errors

I have been going through the python course, and it seems that all of my elif statements always provide syntax errors, and it’s preventing me from running the code and seeing the output. In the error message, the caret always points to the “f” in elif. I am currently on the ground shipping project and running into the issue again.

Here is my code so far. I am only on step 3 where it has you test the math

weight = 6

Ground Shipping

if weight <= 2:
ground_ship = weight * 1.5 + 20
elif weight <= 6:
ground_ship = weight * 3 + 20
elif weight <= 10:
ground_ship = weight * 4 + 20
ground_ship = weight * 4.75 + 20


Below is the error message. this message post preview on the right puts the caret under the e, but in my editor it is under the f

File “”, line 6
elif weight <= 6:
SyntaxError: invalid syntax

1 Like

Take a look at your indentation. elif and else did to be on the same indentation level as their associated if or else they are seen as strays.

I believe this is done by editor preference, some choose to put it at the start of the word that produced an error while others put it at the end.

1 Like

That fixed it! Is there a way to disable the auto-indentation? It’s added every time I am writing an if/else statement.

Good to hear!

What editor are you using?

The built-in CodeAcademy web editor.

Can you post a link to the lesson? I didn’t think the Codecademy editor auto formatted anything.

It’s not just limited to this project. This has been the case for everything I have done in this course so far.

When I type the initial if statement and hit enter, it adds an indent there, and after typing each line and hitting enter to move to the next, it auto-indents each one moving further to the right every time.

Sorry, I was thinking of it indented elif specifically.
I’m not sure if it can be disabled but I’ll try to find out.

From what I’ve found it doesn’t look like there’s any easy way to disable the auto indentation in the CC editor. If I’m seeing it correctly that setting is set in the JS files that render the editor. You can see a list of the available keyboard shortcuts by typing F1 in the editor or ctrl+alt+p.