Your function failed on the message no. It returned 'Shutting down' when it should have returned 'Shutdown aborted'


#1



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


Your function failed on the message no. It returned 'Shutting down' when it should have returned 'Shutdown aborted'


it should print return Shutdown aborthed but it gives me an error, Is it my if statement??


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


#2

OK just found the cause of error is the boolean operator or, but that doesn't make any sense. I'm pretty sure its correct


#3

if you want to use an or operator you need to do comparison at both sides of the or operator:

if 3 > 5 or 4 > 5:

without doing this, python will simply evaluate if 'y' is true, which it is:

if 'y':
     print "Y is true, strings in general are"

so your if condition is currently always true


#4

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