我有一个我希望在每个循环结束时加倍的海龟元素列表,但它什么都不返回
level = 1
number_of_enemies = 5
enemies = []
for i in range(number_of_enemies):`
enemies.append(turtle.Turtle())
while True:
for level < 4
[for enemy in l for enemies in repeat(enemy, level)]
for enemy in enemies:
(do_stuff)
level += 1
答案 0 :(得分:0)
通过enemies = [generate_turtle_object_somehow for i in range(2*l)]
生成一些敌人,使敌人的长度增加一倍。此外,列表推导返回结果列表,因此需要适当地分配。
代码:
level = 1
turtle = "turtle"
number_of_enemies = 5
enemies = []
for i in range(number_of_enemies):
enemies.append(turtle+str(i+1))
#print enemies
while level < 4:
print "level", level
l = len(enemies)
enemies = [turtle+str(i+1) for i in range(2*l)]
print enemies
print len(enemies)
for enemy in enemies:
pass
level += 1