Solved Issue #551 regarding input validation in Connect Four by shrutidoshi94 · Pull Request #552 · wasmerio/Python-Scripts

This PR addresses Issue #551, where the game would crash if a player entered a column number outside the valid range (1–7) or a non-integer value.

The fix ensures the game remains stable by implementing an input validation loop that keeps the player prompted until a valid selection is made.

Changes Made

  • Added Input Validation: Wrapped the column selection in a while loop to catch out-of-bounds integers.

  • User-Friendly Indexing: Adjusted the input logic so users can type 1–7 (human-readable) while the code processes it as 0–6 (zero-indexed).

  • Error Handling: Added a try-except block to handle ValueError in case a user inputs a string or symbol instead of a number.

Testing Performed

  • Out-of-Bounds Test: Entered 8, 0, and -1. The program correctly displayed an error message and re-prompted the user.

  • Type Safety Test: Entered "A" and "!" to ensure the ValueError was caught.

  • Boundary Test: Entered 1 and 7 to ensure the pieces were placed in the correct first and last columns of the array.