Having trouble lining up strings? Keep getting syntax error?

I can’t seem to get my strings to line up when making “if” statements, resulting in syntax errors. What am I doing wrong?


weight = 80 
# Ground Shipping
if weight <= 2:
  cost_ground = weight * 1.5 + 20
  elif weight <= 6:
    cost_ground = weight * 3.00 + 20

The syntax of an if statement relies on specific indentation for any elif and else clauses. It should be indented in the following way-

if a:
elif b:
    dosomething else
elif c:
    do another thing

The indentation is technically valid but but the interpreter does not know how to deal with elif on its own so it throws a syntax error (rather than an indentation error).

So my formats correct?

No, the indentation must be fixed. Then the final line where an there’s an elif with no expression or clause at present.

1 Like

I’m still having trouble… it automatically lines up wrong after the : on a string when I hit enter. Are there indentation settings I have to change somewhere?

Got it, had to manually go back and edit each line. Thanks :+1:

It automatically indents after : so you can write that code block, then you have to manually get yourself out of the block.

1 Like

Yeah i had to go back and edit each line up. At first I couldn’t figure out what I was doing lol

1 Like