'coin' 和 'player_1' 显示为 NoneType 变量,Tic tac Toe 板未显示在控制台中

the 'coin' and the 'player_1' is showing as NoneType variable and the Tic tac Toe board is not displaying in the console

the coin is showing as NoneTYpe player_1 is also showing as Nonetype The Board is not displaying too due to 'coin' issue I want the board to be displayed . Can anyone help me with this?

def tttboard(board):`
    
    board= [' ']*10
    
    print(board[1] + '|' + board[2] + '|' + board[3])
    print('-----')
    print(board[4] + '|' + board[5] + '|' + board[6])
    print('-----')
    print(board[7] + '|' + board[8] + '|' + board[9])
    


`def playornot():`
    
    
    
    alpha=['y','n','Y','N']
    
    
    
    
    print('Would You Like to Tic-Tac-Toe!')
    gamer_choice=input('choose your answer (y/n):')
    
    while gamer_choice not in alpha :
       print('wrong input, enter again')
       gamer_choice=input('choose your answer (y/n):')
       
    if gamer_choice=='N' or gamer_choice=='n' :
           print('Meet you again')
    else:
        print('Let us start the game Tic-Tac-Toe!')
    
    pass




def symbolchoose():
    
       
    
    player_1= ' '
    
    print('choose player_1 symbol')
    player_1= (input('choose a symbol "X" or "O" : '))
    
    while player_1!='X' and player_1!='O' :
        print('wrong input, enter again!')
        player_1=input('choose a symbol "X" or "O" : ')
        
   
        
    if player_1== 'X' :
       player_2= 'O'
           
    else:
        player_2= 'X'
            
             
        
        
    print(f'{player_1} Is chosen by player one')
    print(f'{player_2} is chosen by player two')
        
        
    pass

     
    


import random

def flipit():
    
    flip=random.randint(0,1)
    
    if flip==0:
        print('Player 1 turn')
    else:
        print('Player 2 turn')
    pass



    
while True:
    tboard = [' ']*10
    player_1=symbolchoose()   -----> #Here is the probelm
    coin = flipit()
    playornot()

    
    if coin =='Player 1 turn':----> #Here is the probelm
       tttboard(tboard)


     

the coin is showing as NoneTYpe player_1 is also showing as Nonetype The Board is not displaying too due to 'coin' issue

您使用 player_1=symbolchoose() 调用函数并将 return 值放入变量 player_1。但是,当您定义函数 symbolchoose() 时,您什么都不 return。

因此,不要在函数末尾调用 pass,而是使用 return player_2 或您需要的任何变量。

参见https://www.geeksforgeeks.org/python-return-statement/#:~:text=A%20return%20statement%20is%20used,special%20value%20None%20is%20returned。或 google return。这对正确使用函数很重要!