17 review functionS what's wrong with my code?


#1




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


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

I can't find what I am doing wrong...Please can someone help?


#2

1) IndentationError: because if, elif and else should have four indentations (1 indentation block) -like in example

2) Correct code is:
def shut_down(s):
(1 indentaiton block like example) return shut_down

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

#3

Thank you for your response but still didn't work.
I'll just try again...


#4

after a lot of editing, I got it right!
here's how the code should look:

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


#5

I'm new to this Q&A thing...not sure how to tab the lines of code in here...but, the first "return", "if" "elif" and "else" are tabbed in once, while the "return"s following "if", "elif", and "else" are tabbed twice.


#6

Hi dude, your code does not work


#7

Sorry that it's not working for you. That's the exact code I entered for successful completion.


#8

my code look like this and it was right!

def shut_down(s):
return shut_down

  if (s)=='yes': 
        return "Shutting down"

  elif (s)=='no':  
        return "Shutdown aborted"

   else :
         return "Sorry"

#9

.isjdiajdadosdoooooooooo


#10

hello,

any solution? I tried all of the comments but they are not working.


#11

okey I found it

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

I am sure that I had written same thing before but i don't know this time it accepted. maybe it is about tabs or spaces but I am not sure.


#12

The following code worked for me. Note that tabbing the If,elif and else along with another tab for return

def shut_down(s):
return shut_down
if (s) == "yes":
return "shutting down"
elif (s) == "no":
return "shutdown aborted"
else:
return "Sorry"


#13

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