-2
chessBoard ={'1h':'bking','3e':'wking'} 

def isValidChessBoard(board):
   bking=0
   wking=0
   for v in board.values():
       #bking=0
        if v == 'bking':
            bking = bking + 1
       #wking=0
        if v== 'wking':
            wking= wking + 1
   if bking or wking > 1:
            print('This board is invalid')
   else:
            print('Board is good')


isValidChessBoard(chessBoard)

Hello, everyone. Does anyone have some insight as to why the if statement is executing? It is my understanding that because both bking and wking are less than 1 it should go to the else statement?

MdCAL12
  • 3
  • 2
  • 3
    `or` doesn't work like that. Should've been `bking > 1 or wking > 1` – Sergio Tulentsev Jan 17 '22 at 10:52
  • Does this answer your question? [Why does "a == x or y or z" always evaluate to True?](https://stackoverflow.com/questions/20002503/why-does-a-x-or-y-or-z-always-evaluate-to-true) – Bharel Jan 17 '22 at 12:10

1 Answers1

1

Your or is formatted incorrectly.

Change if bking or wking > 1: to if bking > 1 or wking > 1:.

Bharel
  • 23,672
  • 5
  • 40
  • 80