17. Review: Functions - Whats wrong in here

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")
1 Like

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

Try to remove this line.

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"))
1 Like

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

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.

1 Like

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

1 Like

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

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)

1 Like

@ionatan point noted… thanks for concern …

there is nothing wrong with it itsamartya

1 Like

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

1 Like

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