0

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
1
  • Judging by the error message, you are using Python-2.7, not python -3.x. Please update the tags. Commented Feb 5, 2022 at 0:59

2 Answers 2

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
1
  • can't believe it was that simple, thank you so much ! Commented Feb 4, 2022 at 23:26
0

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.