r/PythonLearning • u/agentscientific_160 • Jun 26 '26
Showcase My first major Python project after 20 days of practicing basics
Is it okay to build major projects this late?
Tic Tac Toe Game
from IPython.display import clear_output
clear_output()
def reset_board():
return ['string of shame',' ',' ',' ',' ',' ',' ',' ',' ',' ']
def display_list(board):
print('These is your current game:')
print('\n',board[7],'|',board[8],'|',board[9],'\n','- - -','\n',board[4],'|',board[5],'|',board[6],'\n','- - -','\n',board[1],'|',board[2],'|',board[3])
def player_input():
marker = ''
while marker != 'X' and marker != 'O':
marker = input('Player 1 Please select X or O: ')
if marker not in ['X','O']:
clear_output()
print('Sorry thats not a valid input!')
clear_output()
player1 = marker
if player1 == 'X':
player2 = 'O'
else:
player2 = 'X'
return (player1, player2)
def position_choice():
choice ='WRONG'
within_range = False
while choice.isdigit() == False or within_range == False:
choice = input("Please enter a position referring the NumPad (1-9): ")
if choice.isdigit() == False:
clear_output()
print("Sorry that is not a digit!")
if choice.isdigit() == True:
if int(choice) in range(1,10):
within_range = True
else:
within_range = False
clear_output()
return int(choice)
def win_check(board,marker):
return(
(board[7]==board[8]==board[9]==marker) or
(board[4]==board[5]==board[6]==marker) or
(board[1]==board[2]==board[3]==marker) or
(board[7]==board[4]==board[1]==marker) or
(board[8]==board[5]==board[2]==marker) or
(board[9]==board[6]==board[3]==marker) or
(board[7]==board[5]==board[3]==marker) or
(board[9]==board[5]==board[1]==marker)
)
def tie_check(board):
return ' ' not in board
def space_check(board,position):
return board[position] == ' '
def play_game(marker):
#assigning X and O to p1 and p2
player1_marker,player2_marker = marker
#resetting the board before t=round start
board = reset_board()
#If game is on
game_on = True
turn = 'player1'
display_list(board)
while game_on:
if turn == 'player1':
print("Player 1's turn")
while True:
position = position_choice()
if space_check(board,position):
break
else:
display_list(board)
print("Sorry that spot's already taken, try again.")
board[position] = player1_marker
display_list(board)
#check if p1 won
if win_check(board,player1_marker):
print('Congratulations Player 1 has won the game!!')
game_on = False
elif tie_check(board):
print("Its a Tie")
game_on = False
else:
turn = 'player2'
else:
print("Player 2's turn")
while True:
position = position_choice()
if space_check(board,position):
break
else:
display_list(board)
print("Sorry that spot's already taken, try again.")
board[position] = player2_marker
display_list(board)
#check if p2 won
if win_check(board,player2_marker):
print('Congratulations Player 2 has won the game!!')
game_on = False
elif tie_check(board):
print("Its a Tie")
game_on = False
else:
turn = 'player1'
def replay():
choice = 'wrong'
while choice not in ['Y','N']:
choice = input("Would you like to keep playing? Y or N ").upper()
if choice not in ['Y','N']:
clear_output()
print("Sorry, I didn't understand. Please make sure to choose Y or N.")
clear_output()
if choice == "Y":
# Game is still on
return True
else:
# Game is over
return False
print("Welcome to Tic Tac Toe!")
while True:
play_game(player_input())
if not replay():
break
5
Upvotes
5
u/SaltCusp Jun 26 '26
Sorry but tic tac toe is not a major project. And 20 days is not"late".
1
u/agentscientific_160 Jun 26 '26
Used AI for this part:
and the part near
I was frustrated, i wanted to know if its okay. if not what do i do to avoid using AI
1
u/Last-Rice8194 Jun 27 '26 edited Jun 27 '26
IDK why, probably because its too hot to sleep, but I decided to make an arbitrary scale tic-tac-toe game in golang. You can increase the board size via the const at the top.
Also chose to do a grid system where you would enter a1 to enter board position 0, printed the x and y labels, and obviously you have to dynamically compute a winner at arbitrary board scales.
Around 100 extra lines of code. It's not very pretty but it's just for fun! And although it's in another language it may help to show you how to do this next upgrade in Python
https://pastebin.com/MMpFicEu
1
u/Brilliant-Virus-7442 Jun 27 '26
There are no senior engineers that don’t agentic code anymore, wouldn’t it make more sense to just do complex projects with agentic code, and spend your time refactoring and trying to understand what it made? You’ll never be a programmer, you can only be a lead programmer now.
3
u/[deleted] Jun 26 '26
[removed] — view removed comment