Ayuda con listas
Publicado por andres alejandro (3 intervenciones) el 16/11/2008 05:59:50
hola a todos necesito ayuda en este lio cuando corro el codigo me sale este error
Traceback (most recent call last):
File "<pyshell#66>", line 1, in <module>
k=a_m("a.txt")
File "C:Documents and SettingsPropietarioEscritorioa_m.py", line 10, in a_m
mat[i][j]=str(f.read(1))
IndexError: list assignment index out of range
el codigo que quiero correr es este
def a_m(a):
#convierte un archivo a matriz
f=open(a,"r")
#iniciar mat
mat=[[0,0,0],[0,0,0],[0,0,0],[0,0,0]]
e=1
i=0
j=0
while(e):
mat[i][j]=str(f.read(1))
if mat[i][j]=="*":
i=i+1
j=0
elif mat[i][j]=="f":
e=0
else:
j=j+1
f.close()
return mat
si alguien me pudiera decir que estoy haciendo mal que ya e intentado mucho tiempo y no doy con el problema gracias
Traceback (most recent call last):
File "<pyshell#66>", line 1, in <module>
k=a_m("a.txt")
File "C:Documents and SettingsPropietarioEscritorioa_m.py", line 10, in a_m
mat[i][j]=str(f.read(1))
IndexError: list assignment index out of range
el codigo que quiero correr es este
def a_m(a):
#convierte un archivo a matriz
f=open(a,"r")
#iniciar mat
mat=[[0,0,0],[0,0,0],[0,0,0],[0,0,0]]
e=1
i=0
j=0
while(e):
mat[i][j]=str(f.read(1))
if mat[i][j]=="*":
i=i+1
j=0
elif mat[i][j]=="f":
e=0
else:
j=j+1
f.close()
return mat
si alguien me pudiera decir que estoy haciendo mal que ya e intentado mucho tiempo y no doy con el problema gracias
Valora esta pregunta


0