0

The start() is for reference use later for my code.

import os
import random
import time
import replit

playing = ['player1', 'player2']

space = ['1', '2', '3', '4', '5', '6', '7', '8', '9']

def draw():
  print('\n ',space[0],'|',space[1],'|',space[2],'  ') 
  print(' ---+---+---')
  print(' ',space[3],'|',space[4],'|',space[5],'  ') 
  print(' ---+---+---')
  print(' ',space[6],'|',space[7],'|',space[8],'\n') 

def ask(prompt):
  ask = input(prompt)
  return ask

def start(): 
  pick = input('Who go first X / O\n>> ') #this is for reference later
  if pick == 'X' or pick == 'x':
    print('selected X') 
  time.sleep(1)
  replit.clear()
  draw()
  play(ask('Choose number\n>> '))

def play(ans):
  if ans == 1:
    space[0] = 'X'
  elif ans == 2:
    space[1] = 'O'   
  draw()

start()
print(space[0])

All of the functions are working properly they are executing fine except for the play() inside it the space[0] = 'X' is not happening, why is that?

Drian La
  • 5
  • 3
  • Just a few things, the ask method should not define ask, return (as int) immediatelly, `return int(input(prompt))`. You don't have to check if your pick is lowercase/uppercase x, just do `pick.lower() == 'x'`. `space[ans]` could be used for indexing, no need for additional if else blocks. – nagyl Jan 12 '21 at 19:51

1 Answers1

0

Because ask returns a string, not an integer.

Scott Hunter
  • 48,888
  • 12
  • 60
  • 101