Hello, I am taking a computer programming class this semester and working on a project. I am trying to read a text file into a 2D list. The text file contains ten rows and ten columns of numbers, either a 0,1,or 2. When i try to read the file it adds the numbers on to the end of the list...this is what i have
def getfromfile():
infile = input("Enter the name of the file with the original state of the network: ")
infile = open(infile,"r")
OLD =[ [" "]*COLUMN for i in range(ROW)]
for line in infile:
for i in range(ROW):
OLD.append(i)
for j in range(COLUMN):
OLD.append(j)
for i in range(ROW):
for j in range(COLUMN):
if i == 0:
OLD[i][j] = DEAD
elif i == 1:
OLD[i][j] = CLEAN
else:
OLD[i][j] = INFECTED
The whole idea is that the list is a network of computers that are infected. OLD is the list of computers that is the network and as each time cycle passes, more computers get infected...i am just having a problem getting the "original state" from the text file...
THANKS!!!