16

5 - 图1

  1. #第 16 题
  2. Flyer[0].step(3)
  3. Dev.turnRight()
  4. Dev.step(5)
  5. Dev.wait(9)
  6. Dev.turnLeft()
  7. Dev.step(8)
  8. Dev.turnLeft()
  9. Dev.step(2)

20

5 - 图2

  1. # 第 20 题
  2. Dev.turnRight()
  3. for i in range(6):
  4. Spaceship.step()
  5. if not Item[1+2*i].broken():
  6. Dev.step(2)
  7. Dev.step(-2)
  8. if not Item[2*i].broken():
  9. Dev.step(-(Spaceship.y - Item[2*i].y))
  10. Dev.step(Spaceship.y - Item[2*i].y)
  11. Spaceship.step()

5 - 图3

21

  1. # 第 21 题
  2. for i in range(6):
  3. if i == 2 or i == 3 or i == 4:
  4. Dev.step()
  5. Dev.step(-1)
  6. Spaceship.step()
  7. if i == 0 or i == 1 or i == 5:
  8. Dev.step(-4)
  9. Dev.step(4)
  10. Spaceship.step()

26

5 - 图4

  1. # 第 26 题
  2. for i in range(3):
  3. Spaceship.turnRight()
  4. for j in range(3):
  5. Spaceship.step(2)
  6. Dev.step(1+i+j)
  7. Dev.step(-(1+j + i))
  8. Spaceship.step(1+i)
  9. Dev.turnRight()

29

5 - 图5

  1. def g(a,n,m):
  2. Spaceship.step(a)
  3. Dev.step(n)
  4. Dev.turnLeft()
  5. Dev.step(m)
  6. Dev.turnRight()
  7. Spaceship.step(m)
  8. Dev.step(-n)
  9. Spaceship.step(4)
  10. Spaceship.turnRight()
  11. Spaceship.step(2)
  12. Dev.step(-4)
  13. g(2,4,1)
  14. Spaceship.step(7)
  15. Spaceship.turnRight()
  16. Dev.turnRight()
  17. g(1,4,2)
  18. g(2,5,1)
  19. Spaceship.step(5)
  20. Spaceship.turnRight()
  21. Dev.turnRight()
  22. g(4,3,3)

30

5 - 图6

  1. def g(n):
  2. if n >= 1:
  3. Dev.step(n)
  4. g(n/2)
  5. Dev.step(-n)
  6. Dev.turnRight()
  7. Dev.step(-n)
  8. Dev.turnLeft()
  9. g(n/2)
  10. Dev.turnRight()
  11. Dev.step(n)
  12. Dev.turnLeft()
  13. g(8)