Bird
Raised Fist0

What will be the output of this move validation snippet if the move is invalid?

medium📝 Analysis Q5 of Q15
LLD - Design — Chess Game
What will be the output of this move validation snippet if the move is invalid?
def validate_move(piece, start, end):
    if piece == 'pawn' and end[1] != start[1]:
        return False
    return True

print(validate_move('pawn', (1, 1), (2, 2)))
ATrue
BFalse
CNone
DError
Step-by-Step Solution
Solution:
  1. Step 1: Analyze condition for pawn move

    Pawn cannot move diagonally unless capturing; here end[1] != start[1] means diagonal move.
  2. Step 2: Check function return for given inputs

    Since end[1] (2) != start[1] (1), function returns False.
  3. Final Answer:

    False -> Option B
  4. Quick Check:

    Invalid pawn diagonal move returns False [OK]
Quick Trick: Pawn diagonal move without capture is invalid [OK]
Common Mistakes:
MISTAKES
  • Assuming diagonal pawn move is valid
  • Ignoring return False condition
  • Confusing coordinates indexing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes