Review: Functions


#1

Please help me fix this. I tried many combinations but still doesnt work and i receive this : Oops, try again. Your shut_down function threw the following error: maximum recursion depth exceeded


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


#2

this:

s == "yes"

should be your if condition, why call the function at the if condition?


#3

I tried this but doesnt work

def shut_down(s):

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

#4

well, that was not what i suggested?


#5

thank you so much :slight_smile: works


#7

I can't figure out what I'm doing wrong here:


#8

the example in the left is just a reminder of syntax, the program you make has a different design then the example.

Please read the instructions, and don't use the example as template, but only as a reminder of syntax


#10

Got it figured out, thanks!


#11

Hey all, not sure why this isn't working:

def shut_down(s):
return s

if s == 'yes':
    return 'Shutting down'

elif s == 'No':
    return 'Shutdown aborted'

else:
    return "Sorry"

#12

a function ends the moment a return keyword is reached

so, the first line of your function content:

return s

hey, a return keyword is reached. Function ends. Your if/elif/else clause is never reached


#15

3 posts were split to a new topic: Review: functions


#16

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