函数修改列表不返回i

2024-10-03 21:25:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着做一个函数来“刷新”一个游戏板,而不是修改它。我的问题是函数正在修改它,我不知道为什么。你知道吗

例如:

def refrescartablero(tablero):
limpiarconsola()
copiatablero=[]
columnas=[" "]
print (copiatablero)
for x in tablero:
    copiatablero.append(x)
for x in range(1,len(copiatablero[0])+1):
    columnas.append(str(x))        
copiatablero.insert(0,columnas)    
for x in copiatablero:
    x.insert(0,"")
    x.insert(len(x), "")
for x in range(1,len(copiatablero)):
    copiatablero[x].insert(1,str(x))
for x in copiatablero:
    print ("_|_".join(x))
tablero=copiatablero
return

这个函数添加了一些东西,使电路板看起来像:

_|_ _|_1_|_2_|_3_|_4_|_5_|_
_|_1_|_ _|_ _|_ _|_ _|_ _|_
_|_2_|_ _|_ _|_ _|_ _|_ _|_
_|_3_|_ _|_ _|_ _|_ _|_ _|_
_|_4_|_ _|_ _|_ _|_ _|_ _|_

但我只需要把它打印出来。问题是列表“tablero”是:

tablero=[[' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ', ' ']]

变成:

tablero= [['', '1', ' ', ' ', ' ', ' ', ' ', ''], ['', '2', ' ', ' ', ' ', ' ', ' ', ''], ['', '3', ' ', ' ', ' ', ' ', ' ', ''], ['', '4', ' ', ' ', ' ', ' ', ' ', '']]

换句话说,我的功能是打印和修改列表,而不仅仅是打印。。。你知道吗

如果有人能帮我就太好了。你知道吗


Tags: 函数in游戏列表forlendefrange