Review Function Syntax Error


#1


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


File "python", line 4
elif shut_down(s == "No"):
^
SyntaxError: invalid syntax
Syntax Error

I expect the function to run accordingly

def shut_down(s):
    if shut_down(s == "Yes"):
        return "Shutting down"
        elif shut_down(s == "No"):
            return "Shutdown aborted"
            else: 
                return "Sorry"


#2

the indent of your code seems a bit off. When you call the function:

shut_down("yes")

s will hold the argument passed on the function call, so you can just compare s with what you want:

s == "yes"

yes and no should also be spelled with lowercase letters


#3

def shut_down(s)
s == 3 + 2


if shut_down("yes"):
    return "Shutting down"
elif shut_down("no"):
    return "Shutdown Aborted"
else:
    return "Sorry."

I tried this but now it gets this error
File "python", line 1
def shut_down(s)
^
SyntaxError: invalid syntax


#4

the indent is still not good, the if, elif and else should be inside the function:

def shut_down(s) # missing : to indicate start of function
s == 3 + 2 # this line is pointless, remove it

# you should compare `s` with the string: s == "yes"
#already told you this? 
#indent the code below better so it is inside the function
if shut_down("yes"):
    return "Shutting down"
elif shut_down("no"):
    return "Shutdown Aborted"
else:
    return "Sorry."

#5

I am sorry I am bad at Indentation can you tell me what you mean?


#7

if you are bad at indention, python is the worst language you can pick to learn.

well, this print statement is in the function:

def example():
   print "i am in inside the function"

this one is not:

def example():
print "i am not inside the function, and will cause an error "

#8

What language do you recommend for me then? Also 'm gonna try it and see if it works.


#9

I tried it and now there is no longer an Indentation error but this pops up.
Oops, try again. Your function failed on the message no. It returned 'Shutdown aborted.' when it should have returned 'Shutdown aborted'


#10

Well, if you are really that bad at indention, you can either learn it, or switch languages. Which language also depends on what you want to build, python is the only of the major languages which uses indent like this

a string returned should be an exact match, you have a full stop (.) at the end, where the exercise doesn't have this


#11

Well I got what you mean by indentation now, also I just want to study a powerful language so I can use it to open up my own Software company :smile: Also let me check if I have a period in mines.


#12

Ty it's done. I got it now.


#13

2 posts were split to a new topic: Review function


#15