我应该写函数randomWorld
。它接受两个整数width和height,分别表示世界的宽度和高度,并返回一个表示世界的字典。我一直在遵循教师算法的想法,但我得到这个
SyntaxError不能赋值给函数调用
这就是我所做的
def randomWorld(width, height):
"""Return a random world"""
world={}
for x in range(width):
for y in range(height):
if random.randint(0,10) < 3:
world.Cell(x,y)=True
return world
我想你只是想:
world[x,y] = True