Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions Connect Four/connectfour.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -26,7 +36,16 @@ 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)))
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):
Expand Down Expand Up @@ -239,4 +258,4 @@ def main():
gamePlayTwoPlayers(player1, player2)


main()
main()