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
You call a function with player_1=symbolchoose()
and put the return
value into the variable player_1. But when you define your function symbolchoose()
you do not return anything.
So instead of calling pass at the end of your functions, use return player_2
or whatever variable you need.
See https://www.geeksforgeeks.org/python-return-statement/#:~:text=A%20return%20statement%20is%20used,special%20value%20None%20is%20returned. or google return. This is important to use functions correctly!