Is it possible to pass a single user input (an int) into an argument to match 2 ints in python?
<p>Basically I'm trying to write a tic tac toe game in python and I'm new to the language. At the moment I'm trying to get the user to input an int which I will then pass into an argument which requires two ints of the same number (as the grid will be a square), to make a grid for the game. If you look in the code below I have hard coded in the arguments (grid_maker(6,6)), but is there a way I can assign the user input into h and w so the grid will be the size the user requests? (The user can input any number they wish e.g. 20, and make a 20 by 20 grid, but they still only need 3 in a row, the code is more for the practice rather than an efficient game).</p>

<p>On a side note would this way be recommended as I will need to check if someone has gotten 3 Xs or Os in a row.</p>

<pre><code>class GameBoard:

def printBoard():
print('Welcome to my tic tac toe game')
("Commented gridInput out as it results in an error ")
#gridInput = int(input('Please enter a number between 5-10 to set the grid dimensions for the game board\n'))

def grid_maker(h,w):
 grid = [[" | " for _ in range(w)] for _ in range(h)]
 return grid

 print ('\n'.join(' '.join(row) for row in grid_maker(6,6)))

def print_grid(grid):
  for row in grid:
    for e in row:
        print (e)
</code></pre>

<p>I am not sure what exactly you want to do, but I guess there are multiple solutions to it. I will just give one possible solution:</p>

<pre><code>def grid_maker(h,w=None):
  if w is None: w=h
  grid = [[" | " for _ in range(w)] for _ in range(h)]
  return grid
</code></pre>

python python-3.x multidimensional-array grid arguments