语法糖吃的有点傻~
import copy
import os
m, n = 10, 10
world = [[0 for _ in range(0, m)] for _ in range(0, n)]
world[0][1], world[1][2], world[2][0], world[2][1], world[2][2] = 1, 1, 1, 1, 1
while True:
os.system('cls')
_world = copy.deepcopy(world)
for i in range(0, m):
for j in range(0, n):
state = 0
if not (i == 0 or j == 0):
state += world[i - 1][j - 1]
if not i == 0:
state += world[i - 1][j]
if not (i == 0 or j == n - 1):
state += world[i - 1][j + 1]
if not j == 0:
state += world[i][j - 1]
if not j == n - 1:
state += world[i][j + 1]
if not (i == m - 1 or j == 0):
state += world[i + 1][j - 1]
if not i == m - 1:
state += world[i + 1][j]
if not (i == m - 1 or j == n - 1):
state += world[i + 1][j + 1]
if state < 2 or state > 3:
_world[i][j] = 0
elif state == 3:
_world[i][j] = 1
print(('\033[47m \033[0m' if _world[i][j] else ' '), end='')
print()
world = copy.deepcopy(_world)
input()