0

I was running some nested if statements and my code was not running the way I wanted it to once it reached a certain if statement. I could not figure out what the problem is, so I isolated the code and ran it and I am still getting the same problem. I simplified the code down to a couple of lines and do not see what I am doing wrong.

reset = input('Enter y or q ')
if reset == 'y' or 'Y':
    print('If executed, reset is', reset)
else:
    print('Else executed, reset is', reset)

When executing the code, the result I get is:

Enter y or q q
If executed, reset is q

I don't understand, my input is q, which sets the variable reset to q. The if statement should only be true is reset == 'y' or 'Y'...I don't get why it is executing.

Thank you for your time.

Austin
  • 114
  • 7
  • You probably want raw_input rather than input, and if it's not obvious from that other answer, if reset == 'y' or reset == 'Y': Is the problem. Good luck! – Ian McGowan Jan 24 '17 at 02:27
  • @IanMcGowan: Question’s tagged with [tag:python-3.x], so `input` isn’t an issue. – Ry- Jan 24 '17 at 02:29
  • Ryan, thanks. I'm one step ahead of Austin on the learning curve, but when SO has been good to me I like to try and answer an easy question. I should make sure to test on both 2 and 3. Thanks for being gentle! – Ian McGowan Jan 24 '17 at 02:41
  • Thank you both! :) – Austin Jan 24 '17 at 02:42

0 Answers0