Review: Functions


#1


I'm trying to figure out what's wrong with my code. I tested my code on Codecademy Labs
to see if it was just a glitch with the page I'm on, but I get the same error , too. :frowning:
Help would be greatly appreciated.:slight_smile:


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

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


Here's my error message:

File "python", line 4
return "Shutting Down"
------- ^
IndentationError: expected an indented block

I added those underlines in the error code so you can see where the arrow below return exactly was.

`


#2

The key to this error message is IndentationError: expected an indented block.

If you make sure your indentation is correct then this code should work. Remember that all of the code within a function should be indented, and any code within if/elif/else should be indented under the if/elif/else.


#3

Like this? reference from:
http://www.peachpit.com/articles/article.aspx?p=1312792&seqNum=3

def shut_down(s):
   
if s == "yes":
 return "Shutting Down"

elif s == "no":
   return "Shutdown aborted"
    
else:
   return "Sorry"

Now I get an error code that says:

File "python", line 3
--- if s == "yes":
----^
IndentationError: expected an indented block

I used the underlines so you can see where that arrow is under if.

The instructions they put in for this lesson are quite confusing, too. :confused:
Oh yes, I did try what you said, but it didn't work unfortunately.


#4

That's almost correct! The if/elif/else indentation is correct, but all of this code

if s == "yes":
 return "Shutting Down"

elif s == "no":
   return "Shutdown aborted"
    
else:
   return "Sorry"

needs to be indented within the def shut_down(s): function, like this:

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

#5

Ok, I understand and I got it to work! Thanks for the help! :slight_smile:


#6

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