From f1cb1ddc7490560f1fbbd4fedc0111e6ad21447a Mon Sep 17 00:00:00 2001 From: Vincent Rodley Date: Fri, 1 Aug 2025 10:51:40 +1200 Subject: [PATCH] try fix inputs --- main.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 044d978..94a6e3b 100644 --- a/main.py +++ b/main.py @@ -43,6 +43,19 @@ def printBoard(board): print(f"===============\n{toPrint[:-1]}\n===============") +def getIntInput(prompt): + success = False + inp = "" + while not success: + inp = input(prompt) + try: + inp = int(inp) + break + except: + print("Only integers allowed") + + return inp + # Board will be 7x6. # O = open, R = red, Y = yellow @@ -65,10 +78,7 @@ turn = 'R' while playing: clear() - try: - chosenColumn = int(input(f"{turn} where do you want to drop your tile? 1-7.\n>>> ")) - except Exception as e: - print("Please enter a positive integer.") + chosenColumn = getIntInput(f"{turn} where do you want to drop your tile? 1-7.\n>>> ") try: tile = findLowest(board, chosenColumn)