17/19 Why isn't my code working?


#1


https://www.codecademy.com/en/courses/python-beginner-c7VZg/4/1?curriculum_id=4f89dab3d788890003000096

When I submit the code it just says "Line 6:Invalid Syntax"


Code below-


 
def shut_down(s):
     if s == "yes":
      return "Shutting down"
     elif s == "no":
      return "Shutdown aborted" 
else:
return "sorry"


#2

Hello @arva2121
This program have indentation problem.
We need to fix the indentation here,

EDITED--
Indentation is used to define different code blocks.
When we define a function, conditional clause , Loops, we actually define different blocks of code.

When one block of code resides inside of another, we need to space out internal block by some spaces,

Like here, inside the function block, We have conditional clause, so we need to indent it using four spaces, also the code lines inside the if/elif/else need to be indented by 4 spaces.

We can use this template..

def someFunction(some parameter):
    if test:
        #Code
    elif test:
       #Code 
    elif test:
        #Code  
    else:
        #code

#3

What have you learned so far with respect to Python syntax and the need for consistent indentation of code blocks? Are you aware of the importance of this to context and scoping?


#4

Thanks! When I asked the question it wasn't indented. Now it works!


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.