所以我试图创建一个连接四个游戏,每次玩家'O'玩我想询问用户是否想要保存并且我希望excel文件显示('X' as '1')('O' as ' 2')(''作为'0')。这里的问题是我必须反转list1才能将list1的行转换为excel文件上的列(excel将板的列显示为行),当我反转list1时,excel列中的每个单元格都变为'0 ' (即使有一个 'X' 或 'O'),而当 list1.reverse() 不存在时,它打印得很好,但列的单元格的顺序是相反的。这是为什么?
if turn == 'X':
turn = "O"
else:
ans = input('Press s to save your progress. press any other key to continue : ')
if ans == 's':
nop = input('Type in the name of the file :')
f = open(nop + '.csv', 'a', newline ='')
for y in range(len(my_board)):
list1 = []
for l in range(len(my_board)):
if my_board[y][l] == 'X':
list1.append('1')
elif my_board[y][l] == 'O':
list1.append('2')
else:
list1.append('0')
writer = csv.writer(f)
list1.reverse()
writer.writerow(list1[l])
f.close()
turn = 'X'