0

Why doesn't this code produce intended output

for i in range(65,91):
  if result not in (chr(74),chr(75) :
   f=0
  else :
   f=1
Akhil Nadh PC
  • 574
  • 1
  • 7
  • 24
  • 1
    `or` in Python is a boolean operator, not a conjunction; it does far less than the English conjunction `or`, and it doesn't do what you're trying to do there. – user2357112 Aug 18 '17 at 06:48
  • (Short circuiting isn't relevant at all here.) – user2357112 Aug 18 '17 at 06:48
  • The same property that allows short circuiting (`(True or x) == True`) leads to a slightly odd but useful behaviour: `or` returning one of its operands, not necessarily a bool. In this case it led to some confusion, as producing a bool wouldn't have led to any characters matching. Very few languages to multimatching in the way shown; I think Prolog might. In the example a regex `[IJ]` might have been more fitting. – Yann Vernier Aug 18 '17 at 07:05
  • How do i make this code correct ? – Akhil Nadh PC Aug 18 '17 at 07:11

0 Answers0