17. Review: Functions - Whats wrong in here


#1

Its not printing desired result/ output, but passing me ..

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

4/17 Review: Functions help
#2

I think that you don't need to call the function here:

Try to remove this line.


#3

If you're expecting the interpreter to print something, it's not going to happen. The return it's not going to print anything to the console, just returning a value under the hood. If you want it to print something before "Shutting down" you can just do something like this:

if s == "yes":
    print("Shutting down...")
    # Here you could call a function that shuts down the PC/program

The line there is OK. If you just want the code you already have to print something, you should enclose your last line inside a print() statement.

print(shutdown("yes"))

#4

Thanks Mate, Have :chocolate_bar: from me .. Because it worked.. :wink:


#5

If you read the instructions they say only to create the function shut_down. There is no need to print something. It's ok but it's not mandatory.


#6

Oh, I didn't have in mind the instructions, my bad. Since @itsamartya wanted it to print something, I just went on and replied.


#7

@julietaatanasova @dnlsrl i know that there is no need to printing, am just trying that.. Thanks for your help ..


#8

I'd claim it's preferable to print the result of the function instead of modifying the function.

print shut_down('yes')

That way your function doesn't have any side effects that it isn't supposed to have (printing)


#9

@ionatan point noted.. thanks for concern ..


#10

there is nothing wrong with it itsamartya


#11

I had this exact problem, please DON'T CALL the shut_down function.


#12

still i am not getting o/p
i wrote the same code written above also not calling the function at the end


#17