Nov 9, 2019 in Tutoring

Python projects

The lessons that I will be conducting will be very hands on and will be doing various project e.g making a suduko game then have an algorithm to also solve the suduko game that you created and also projects like tic tac toe etc, Below is the algorithm

Ntshembo Hlongwane

Tutor

45 $ / session

  • 0 Thank you!
  • 0 Testimonial
  • 1 Publication: 11 likes 3 shares
Article cover

 #First Milstone Project
#Creating Tic Tac Toe Game
#Part 1 of the project
#Aim for part1 is to create the board of the game
from IPython.display import clear_output
def display_board(board):
    clear_output()
    print(board[6] + '|' + board[7] + '|' + board[8]) #The print statements that I have here are the ones that are creating my tic tac toe board
    print('-----')#This are the border lines that cuts through the board making it into 3 lines     
    print(board[3] + '|' + board[4] + '|' + board[5])
    print('-----')
    print(board[0] + '|' + board[1] + '|' + board[2])
    

        
        
        
    

#Part2 of the project
#Aim is to get player input

Did you know that you can also talk with the author of this article ?

Ntshembo Hlongwane

Tutor

45 $ / session

  • 0 Thank you!
  • 0 Testimonial
  • 1 Publication: 11 likes 3 shares

def player_input():
    marker = input("Player 1 do you want to be 'X' OR 'O'? ") #This takes in the desired variable from Player1 that is 'X' OR 'Y'
        
        
    player1 = marker
    if player1 == 'X':
        player2 = 'O'
        
    else:
        player2 = 'X'
        
    return "Player2 you are the gonna be: " + player2 #This output will show you what variable player2 will be using due to playe1's choice


    
def place_marker(board, marker, position):
    board[position] = marker
    
place_marker(test_board, '$', 1)
display_board(test_board)

def win_check(board, mark):
    #Win Tic Tac Toe?
    #All rows, and check to see f they all share the same marker?
    #And also check the diagonals

    
    
    return ((board[7] == mark and board[8] == mark and board[9] == mark) or # across the top
    (board[4] == mark and board[5] == mark and board[6] == mark) or # across the middle
    (board[1] == mark and board[2] == mark and board[3] == mark) or # across the bottom
    (board[7] == mark and board[4] == mark and board[1] == mark) or # down the middle
    (board[8] == mark and board[5] == mark and board[2] == mark) or # down the middle
    (board[9] == mark and board[6] == mark and board[3] == mark) or # down the right side
    (board[7] == mark and board[5] == mark and board[3] == mark) or # diagonal
    (board[9] == mark and board[5] == mark and board[1] == mark)) # diagonal


def choose_first():
    flip = random.randint(0, 1)
    if flip == 0:
        return 'Player 1'
    
    else:
        return 'Player 2'
    
    
def space_check(board, position):
    
    return board[position] == ''
    

    def full_board_check(board):
        
        for i in range(1, 10):
            if space_check(board, i):
                return False
            
        return True
    

def reply():
    position = 0
    
    while position not in [1, 2, 3, 4, 5, 6, 7, 8, 9] or not space_check(board, position):
        position = int(input('Choose a position(1-9)'))
        
        
    return position


def choice():
    play_again = input("Want to play again? Yes or No")
    
    retutn play_again = 'Yes'
    
    

    print("Welcome to the Tic Tac Toe Game")
    #While loop to keep running the game
    
    while True:
        
        #Play The Game
        
        ##Set everything up(Board, whos first, choice markers)
        the_board = [' '] * 10
        player1_marker, player2_marker = player_input()
        turn = choose_first()
        
        print(turn + ' will go first.')
        
        play_game = input('Ready to play!')
        
        if play_game = 'Yes':
            game_on = 'True'
            
        else:
            game_on = 'False
            
            
        ## Game Play
        
        while game_on:
            if turn == 'player1':
                #show the board
                display_board(the_board)
                
                #choose a position
                position = player_input(the_board)
                
                place_marker(the_board, player1_marker, position)
                
                
                #check if the is a win
                if win_check(the_board, plater1_marker, position):
                    display_board(the_board)
                    print('Player1 Has Won!!!!!')
                    game_on = False
                
                
                else:
                    if full_board_check(the_board):
                        display_board(the_board)
                        print('Tie Game!')
                        
                        game_on = False
                        
                    else:
                        turn = 'player2'
                #or check if there is a tie
                
                #No tie and no win? Then next player's turn
                
                ###Playe1 One Turn
                
                
                else:
                     #show the board
                display_board(the_board)
                
                #choose a position
                position = player_input(the_board)
                
                place_marker(the_board, player2_marker, position)
                
                
                #check if the is a win
                if win_check(the_board, plater2_marker, position):
                    display_board(the_board)
                    print('Player2 Has Won!!!!!')
                    game_on = False
                
                
                else:
                    if full_board_check(the_board):
                        display_board(the_board)
                        print('Tie Game!')
                        
                        game_on = False
                        
                    else:
                        turn = 'player1'
                #or check if there is a tie
                
                #No tie and no win? Then next player's turn
                
                ###Playe1 One Turn
                
                 '
        
        
        if not chioce()
            break
    
    
    #Break out of the while loop on replay

Related articles

Article cover
Tutoring by gail

Dyslexic students and all students can benefit from tutoring

Gail Becker  | 16 November, 2019

Article cover
Online Tutoring: saving money

In-person tutors cost twice as much as online tutors.

WikiExpert   | 16 November, 2018

Article cover
Mandy's Tutoring

I have decided to use my education to make some money to save up for college. I want to be successful and get accepted into

Mandy Pina  | 19 April, 2020

Article cover
Tutoring without any borders.

Winner of TutorPreneur Hero Award explains why online tutoring is the best career he's ever had.

WikiExpert   | 12 September, 2019