这是我的代码,似乎临时矩阵没有正确更新,但我无法弄清楚原因。我是python的新手,真的很难解决这个问题。
cell = [[0 for i in range(10)] for j in range(10)]
temp=[[0 for i in range(10)] for j in range(10)]
def load():
cell[1][3]=1
cell[2][3]=1
cell[3][3]=1
def cycle():
for x in range(10):
for y in range(10):
checkSurroundingAndChange(x,y)
def checkSurroundingAndChange(i,j):
surrounding=0
if i-1>=0 and j+1<10 and cell[i-1][j+1] == 1: surrounding= surrounding+1
if j+1<10 and cell[i][j+1] == 1: surrounding= surrounding+1
if j+1<10 and i+1<10 and cell[i+1][j+1] == 1: surrounding= surrounding+1
if i-1>=0 and cell[i-1][j] == 1: surrounding= surrounding+1
if i+1<10 and cell[i+1][j] == 1: surrounding= surrounding+1
if j-1>=0 and i-1>=0 and cell[i-1][j-1] == 1: surrounding= surrounding+1
if j-1>=0 and cell[i][j-1] == 1: surrounding= surrounding+1
if j-1>=0 and i+1<10 and cell[i+1][j-1] == 1: surrounding= surrounding+1
if cell[i][j]==0 and surrounding==3:temp[i][j]==1
elif cell[i][j]==1 and surrounding<2:temp[i][j]==0
elif cell[i][j]==1 and (surrounding==2 or surrounding==3):temp[i][j]==1
elif cell[i][j]==1 and surrounding>3:temp[i][j]==0
for i in range(10):
print (cell[i])
print ("////////////////////////////////////////////////////////////////")
load()
cycle()
for i in range(10):
print (temp[i])
答案 0 :(得分:1)
你这里有module.exports = {
create: function (req, res) {
User.findOne({name: req.param('name')}).exec(function findOneCB(err, found) {
if (err) return res.negotiate(err);
if (!found) {
User.create(req.params.all(), function userCreated(err, user) {
if (err) res.negotiate({error:err});
return res.ok(user);
});
} else {
return res.negotiate({error:new Error("USER_EXIST")});
}
});
}
};
个太多了
=
意味着Python正在进行比较并丢弃结果。
这应该是一项任务。即。
temp[i][j]==1
案例设置为temp[i][j] = 1
填写代码使得发现这样的bug变得更加困难。您应该尝试找到更优雅的方式来实现0