0

I am trying to make a tic-tac-toe game. I have this code:


row1 = [' ',' ',' ']
row2 = [' ',' ',' ']
row3 = [' ',' ',' ']
x = ""
y = ""
def screen(row1,row2,row3):
    print(row1)
    print(row2)
    print(row3)
def inputter():
    x = ""
    y = ""
    acceptable = [0,1,2]
    if x not in acceptable and y not in acceptable:
        x = int(input("enter row number:" ))
        y = int(input("enter position:" ))
    row[x][y] = 'X'
    screen(row1,row2,row3)

inputter()

Where it says row[x][y] = 'X', I want to make it so that either row1, row2 or row3 will get updated, depending on the value of x.

But instead, I get an error that says NameError: name 'row' is not defined. How can I fix the problem?

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
  • 2
    Don't use 3 variables `row1`, ... , but only one: `row = [[' ',' ',' '], ... , ... ]` ; then your code should work. – Swifty Apr 11 '23 at 06:56
  • Worked like a charm, Beautiful. I can work with this. Thanks. – ranjit abraham Apr 11 '23 at 07:03
  • For future questions, please read [ask]. I edited the question to show proper style for asking a question here. We do not want to hear about you; we want to hear about the problem directly; and we want a clear, directly asked question. – Karl Knechtel Apr 11 '23 at 08:35

0 Answers0