try fix inputs

This commit is contained in:
Vincent Rodley 2025-08-01 10:51:40 +12:00
parent b63c52c22b
commit f1cb1ddc74

18
main.py
View File

@ -43,6 +43,19 @@ def printBoard(board):
print(f"===============\n{toPrint[:-1]}\n===============") 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. # Board will be 7x6.
# O = open, R = red, Y = yellow # O = open, R = red, Y = yellow
@ -65,10 +78,7 @@ turn = 'R'
while playing: while playing:
clear() clear()
try: chosenColumn = getIntInput(f"{turn} where do you want to drop your tile? 1-7.\n>>> ")
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.")
try: try:
tile = findLowest(board, chosenColumn) tile = findLowest(board, chosenColumn)