code below works well but i want to change 'input(row, col)' to (1, 1) so i can modify value inside code without input, but when i change it it gives this error
AttributeError: 'tuple' object has no attribute 'split'
what is the solution? thank you.
import random
class Tic:
def __init__(self):
self.board = []
def create_board(self):
for i in range(8):
row = []
for j in range(8):
row.append('-')
self.board.append(row)
def fix_spot(self, row, col, player):
self.board[row][col] = player
def show_board(self):
for row in self.board:
print(row)
def start(self):
player = 'O'
T.create_board()
row, col = list(map(int, input("row, col: ").split()))
self.fix_spot(row -1, col-1, player)
T.show_board()
T = Tic()
T.start()
asked Feb 4, 2022 at 23:20
-
Judging by the error message, you are using Python-2.7, not python -3.x. Please update the tags.DYZ– DYZ2022年02月05日 00:59:10 +00:00Commented Feb 5, 2022 at 0:59
2 Answers 2
It seems that all you need to do is replace the line
row, col = list(map(int, input("row, col: ").split()))
with
row, col = (1,1)
answered Feb 4, 2022 at 23:22
-
can't believe it was that simple, thank you so much !ddd_newus– ddd_newus2022年02月04日 23:26:52 +00:00Commented Feb 4, 2022 at 23:26
Since you don't use row
and col
elsewhere in the function, you could put the value direct in the fix_spot
arguments
def start(self):
player = 'O'
T.create_board()
self.fix_spot(0, 0, player)
T.show_board()
Or set a default value in fix_spot
def fix_spot(self, player, row=0, col=0):
self.board[row][col] = player
def start(self):
player = 'O'
T.create_board()
self.fix_spot(player)
T.show_board()
answered Feb 8, 2022 at 9:12
lang-py