-2

For some reason, all of my "if's" and "elif's" come back true no matter what

nyornj = raw_input("select ny or nj please")
newyork="NY" or "nj"
newjersey="NJ" or "nj"
if nyornj==newyork:
    print "New York was input"
if nyornj==newjersey:
    print "New Jersey was input"

Nothing seems to be working, any ideas why this would always come back true?

driedupsharpie
  • 133
  • 2
  • 10
  • It's short circuiting to the first condition so it's always comparing to `"NY" or "NJ"`, you could've tested this if you'd printed out `newyork` and `newjersey`, anyway it makes more sense to uppercase or lowercase your input and test against a single value – EdChum Sep 08 '15 at 12:21
  • ah I see, is there any way to not have this happen but keep the two pairs of "or's"? – driedupsharpie Sep 08 '15 at 12:22
  • Why do you need `or`? just uppercase or lowercase every thing and test against a single str representation – EdChum Sep 08 '15 at 12:23

1 Answers1

0

Instead of comparing with two different value, use str.lower() to convert to all lowercase and then compare.

nyornj = raw_input("select ny or nj please")
newyork="ny"
newjersey="nj"
if nyornj.lower()==newyork:
    print "New York was input"
if nyornj.lower()==newjersey:
    print "New Jersey was input"
Ahsanul Haque
  • 10,676
  • 4
  • 41
  • 57