From 4e3616f4ab7b35711368b528579cf86ca851d827 Mon Sep 17 00:00:00 2001 From: Shruti Doshi Date: Tue, 24 Feb 2026 14:06:29 +0530 Subject: [PATCH 1/2] Solved Issue #551 regarding input validation in Connect Four --- Connect Four/connectfour.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Connect Four/connectfour.py b/Connect Four/connectfour.py index c5fd146e..7d2959d7 100644 --- a/Connect Four/connectfour.py +++ b/Connect Four/connectfour.py @@ -6,7 +6,17 @@ def gamePlayTwoPlayers(p1, p2): win = "" while win == "": - column = int(input("{}'s turn. Enter which column you would like to drop your piece into: ".format(p1))) + while True: + try: + choice = int(input("{}'s turn. Enter column (1-7): ".format(p1))) + if 1 <= choice <= 7: + column = choice - 1 + break + else: + print("Invalid column! Please choose a number between 1 and 7.") + except ValueError: + print("That's not a number! Please enter a digit from 1 to 7.") + connectFourBoard(column, "X") if check_vertical_win(p1, p2, column): @@ -27,6 +37,16 @@ def gamePlayTwoPlayers(p1, p2): break column = int(input("{}'s turn. Enter which column you would like to drop your piece into: ".format(p2))) + while True: + try: + choice = int(input("{}'s turn. Enter column (1-7): ".format(p2))) + if 1 <= choice <= 7: + column = choice - 1 + break + else: + print("Invalid column! Please choose a number between 1 and 7.") + except ValueError: + print("That's not a number! Please enter a digit from 1 to 7.") connectFourBoard(column, "O") if check_vertical_win(p1, p2, column): From 83a376b20041630d22d790f1eb365c66a5603b2e Mon Sep 17 00:00:00 2001 From: Shruti Doshi <166780492+shrutidoshi94@users.noreply.github.com> Date: Tue, 24 Feb 2026 14:23:54 +0530 Subject: [PATCH 2/2] Update input prompt for column choice in game --- Connect Four/connectfour.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Connect Four/connectfour.py b/Connect Four/connectfour.py index 7d2959d7..39de6c5b 100644 --- a/Connect Four/connectfour.py +++ b/Connect Four/connectfour.py @@ -36,7 +36,6 @@ def gamePlayTwoPlayers(p1, p2): print(check_negative_diagonal_win(p1, p2)) break - column = int(input("{}'s turn. Enter which column you would like to drop your piece into: ".format(p2))) while True: try: choice = int(input("{}'s turn. Enter column (1-7): ".format(p2))) @@ -259,4 +258,4 @@ def main(): gamePlayTwoPlayers(player1, player2) -main() \ No newline at end of file +main()