1

Whenever I run this I get the third option when it should be returning the first, since s = 'yes'. What is going wrong here?

def shut_down(s):
    if s is 'yes':
        return 'Shutting down...'
    elif s is 'no':
        return 'Shutdown aborted!'
    else:
        return "Sorry, I didn't understand you"

ans = 'Yes'
s = ans.lower()
shut_down(s)
1

2 Answers 2

5

Change

if s is 'yes':

to

if s == 'yes':

and

elif s is 'no':

to

elif s == 'no':

While is is a valid operator, it is not the one to use here (it compares object identity instead of comparing the character sequences).

Sign up to request clarification or add additional context in comments.

Comments

4

is tests for identity, not equality. To test if a string is equal to yes use s=='yes'

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.