Function - HELO


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/learn-python/lessons/functions/exercises/review-functions?action=lesson_resume&link_content_target=interstitial_lesson

<In what way does your code behave incorrectly? Include ALL error messages.>
File “python”, line 2
if shut_down() == “yes”:
^
IndentationError: expected an indented block

<What do you expect to happen instead?>


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

#2

Hi @arcjumper58551,

Everything within the function definition after its header needs to be indented.

Also, you should not be calling the shut_down function from within. Instead, test the value that is passed via the function parameter, s. For example, you need to change this …

if shut_down() == "yes":

… to this …

  if s == "yes":

This also needs to be changed …

elif shut_down() == "no":

#3

In Python they use a four-spaces indentation to idenify a block of code.

def shut_down(s):
    #4 spaces start of the FUNCTION-block
    #shutdown function is defined as having 1 PARAMETER s
    #this =s= PARAMETER is used as =local= VARIABLE
    #within the FUNCTION-block
    if s == "yes":  #checking the VALUE of the s-VARIABLE
        #8-spaces start of the IF code-block
        return 'Shutting down'
    #4-spaces so IF code-block ends
    elif s == "no":
        #8-spaces start of the IF code-block
        return 'Shutdown aborted'
    #4-spaces so ELIF code-block ends
    else:
        #8-spaces start of the IF code-block
        return 'Sorry'
    #4-spaces so ELSE code-block ends
#end of shut_down FUNCTION
#When calling the shut_down FUNCTION
#and as the shutdown() function was defined as having 1 PARAMETER =s=
#you will have to provide 1 so-called ARGUMENT
#in this case the string "yes"
print shut_down("yes")

========= as an EXTRA ============
As the shut_down() function uses the RETURN statement
calling the shut_down() function
like
shut_down(“yes”)
the shut_down() function RETURN’s the =result= with NODISLAY

To get a DISPLAYed result you can do 2 things
-1 the direct way, using the print-statement
print shut_down("yes")

OR

-2 indirectly by first catching the RETURNed result in a VARIABLE
the_Result =shut_down("yes")
and then do the DISPLAY
print the_Result


#4

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