如何解决如何实现计数器以动态创建井字棋盘
我正在创建一个井字棋盘,用户可以在其中输入行和列。它适用于标准的 3x3,但我想把它做成 99x99,如果我愿意的话。它适用于该问题,但问题是您添加的每一行的列都会增加 1。例如,要制作 6x6,您需要输入 9 列而不是 6 列。我想知道应该添加什么以使其可以自动执行,而无需用户进行硬输入。
代码在这里:
class toe:
marker = '|'
def __init__(self,row,col):
self.row = row
self.col = col
def create_board(self):
d = self.col + 2
final = []
board = ['-' * d for i in range(self.row)]
print(board)
for i in board:
for j in enumerate(i):
excel = list(j)
if excel[0] % 2 != 0:
excel[1] = self.marker
final.append(excel[1])
arr2 = [final[l:l+d] for l in range(0,len(final),d)]
for m in arr2:
print(''.join(m))
def main():
print('to make a correct board after a 3x3,add 1 to the columns. Ex: 4x4 is 4 rows and 5 columns')
print('Ex: 5x5 is 5 rows and 7 columns. 6x6 is 6 rows 9 columns')
row = int(input('number of rows: '))
col = int(input('number of columns: '))
create = toe(row,col)
create.create_board()
if __name__ == '__main__':
main()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。