Aug-04-2020, 04:51 AM
Basically, I'm just trying to understand the logic for the nested loop inputs and outputs. The first nested loops seems to append either a # or a space for 20 values 60 times. So, I understand that I'm inputting either a # or space 20 times per row? What confuses me is the second nested for loop. The WIDTH and HEIGHT are inverted. You start off X with width and then y with height. I don't understand this. In my second nested loop I tried to make the range of the outer loop WIDTH and the inner HEIGHT, but I get an indexing error but I don't understand why? I'm just using the same indexing I used in the previous? How come I have to invert the WIDTH AND HEIGHT for the second nested loop?
WIDTH = 60
HEIGHT = 20
nextCells = []
for x in range(WIDTH):
column = []
for y in range(HEIGHT):
if random.randint(0,1):
column.append('#')
else:
column.append(' ')
nextCells.append(column)
while True:
print('\n\n\n\n\n')
currentCells = copy.deepcopy(nextCells)
for y in range(HEIGHT):
for x in range(WIDTH):
print(currentCells[x][y],end='')
print()
