[英]How to split int value without input?
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下面的代码运行良好,但我想将 'input(row, col)' 更改为 (1, 1) 这样我就可以在没有输入的情况下修改代码中的值,但是当我更改它时会出现此错误
AttributeError: 'tuple' object has no attribute 'split' AttributeError: 'tuple' object 没有属性 '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()
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)
Since you don't use row
and col
elsewhere in the function, you could put the value direct in the fix_spot
arguments由于您不在 function 的其他地方使用row
和col
,您可以将值直接放在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
或者在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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.