2 Replies - 277 Views - Last Post: 28 June 2013 - 12:02 PM Rate Topic: -----

#1 DblAAssassin  Icon User is offline

  • D.I.C Head

Reputation: 32
  • View blog
  • Posts: 247
  • Joined: 11-May 13

Input "No" Error

Posted 28 June 2013 - 11:01 AM

So I'm learning Python from, Codecademy (Great Site), any ways here is the lesson., and here is the code...
def shut_down(string):
    if string == "Yes" or "yes" or "YES":
        return "Shutting down..."
    elif string == "No" or "no" or "NO":
        return "Shutdown aborted!"
    else:
        return "Sorry, I didn't understand you."


The error is...

Quote

Oops, try again! It looks like the input "No" does not return "Shutdown aborted!"


Yes I have the exclamation point, I really don't have a clue what my issue is. Or it may be the site messing up again, it happen occasionally. Thanks for all help beyond this point! :)/>

This post has been edited by DblAAssassin: 28 June 2013 - 11:03 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Input "No" Error

#2 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7655
  • View blog
  • Posts: 12,909
  • Joined: 19-March 11

Re: Input "No" Error

Posted 28 June 2013 - 11:14 AM

if string == "Yes" or "yes" or "YES":



This doesn't mean what you think it means.

Clue:
if "yes":
  print "Yes is True!"
else:
  print "Yes is False"


Was This Post Helpful? 0
  • +
  • -

#3 woooee  Icon User is offline

  • D.I.C Head

Reputation: 21
  • View blog
  • Posts: 78
  • Joined: 21-November 12

Re: Input "No" Error

Posted 28 June 2013 - 12:02 PM

You want to use
if string.lower() == "yes":
## or 
if string.lower() in ("yes", "y", "ok"): 
Note that a not empty string always returns True, so 'or "yes"' always returns a True.

This post has been edited by woooee: 28 June 2013 - 12:06 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1