ICode国际青少年编程竞赛- Python-5级训练场-函数入门
1、
def jiqiren():
Dev.step(4)
Dev.step(-4)
jiqiren()
Spaceship.step(3)
jiqiren()
Spaceship.step(2)
jiqiren()
Spaceship.step(4)
jiqiren()
Spaceship.step(2)
jiqiren()
Spaceship.step(3)
jiqiren()
2、
def get_item():
Dev.step(-5)
Dev.step(5)
get_item()
Spaceship.step(2)
get_item()
Spaceship.step(3)
Spaceship.turnLeft()
Spaceship.step(1)
get_item()
Spaceship.turnRight()
Spaceship.step(2)
get_item()
Spaceship.step(4)
Spaceship.turnLeft()
Spaceship.step(1)
get_item()
3、
def func():
#注意函数内部的代码需要缩进4格
Dev.step(-4)
Dev.step(4)
func()
Spaceship.step(2)
Spaceship.turnLeft()
Spaceship.step(1)
func()
Spaceship.turnLeft()
Spaceship.turnLeft()
Spaceship.step(2)
Spaceship.turnLeft()
Spaceship.step(2)
func()
Spaceship.step(3)
Spaceship.turnLeft()
Spaceship.step(1)
func()
4、
def move():
Dev.step(3)
Dev.step(-3)
move()
Spaceship.step(3)
Spaceship.turnLeft()
Spaceship.step(3)
move()
Spaceship.turnRight()
Spaceship.step(2)
Dev.turnRight()
move()
Spaceship.turnRight()
Spaceship.step(3)
move()
5、
def move():
for i in range(4):
Dev.step(2)
Dev.turnLeft()
Spaceship.step(2)
move()
Spaceship.turnRight()
Spaceship.step(4)
Dev.turnRight()
move()
Spaceship.turnRight()
Spaceship.step(3)
Spaceship.turnLeft()
Spaceship.step(2)
Dev.turnRight()
move()
6、
def move():
Dev.turnLeft()
Dev.step(2)
Dev.turnLeft()
for j in range(4):
Dev.step()
Dev.turnRight()
Dev.step()
Dev.turnLeft()
Dev.step(2)
Dev.turnLeft()
Dev.step(2)
move()
Dev.step(5)
move()
Dev.step(4)
move()
Dev.step(5)
move()
Dev.step(2)
7、
def a(b):
Spaceship.step(b)
Dev.step(3)
Dev.turnLeft()
Dev.step(2)
Dev.turnRight()
Spaceship.step(2)
Dev.step(-3)
a(0)
a(3)
a(2)
a(4)
8、
def move():
Dev.step(3)
Dev.turnRight()
Dev.step(2)
Dev.turnLeft()
Spaceship.step(2)
Dev.step(-3)
move()
Spaceship.step()
Spaceship.turnRight()
Spaceship.step()
Dev.turnRight()
move()
Spaceship.turnRight()
Spaceship.step(3)
Dev.turnRight()
move()
Spaceship.step()
9、
def move():
Dev.step(4)
Dev.turnRight()
Dev.step(2)
Dev.turnLeft()
Spaceship.step(2)
Spaceship.turnLeft()
Spaceship.step()
Dev.step(-3)
move()
Spaceship.turnLeft()
for i in range(2):
Spaceship.turnLeft()
Spaceship.step(2)
move()
Spaceship.turnLeft()
for i in range(2):
Spaceship.turnLeft()
Spaceship.step(1+2*i)
move()
Spaceship.turnRight()
Spaceship.step(2)
move()
10、
def move():
Dev.step(3)
for i in range(2):
Dev.turnRight()
Dev.step(2+i)
Dev.step(3)
move()
Dev.step(-2)
Dev.turnLeft()
Dev.step(4)
move()
for i in range(2):
Dev.step(1+2*i)
Dev.turnLeft()
move()
Dev.step(2)
Dev.turnLeft()
Dev.step(1)
move()
11、
def move():
Spaceship.turnLeft()
for i in range(2):
Spaceship.step(3-i)
Spaceship.turnRight()
Spaceship.step(3)
Spaceship.step()
move()
Spaceship.turnLeft()
Spaceship.step(6)
move()
Spaceship.step(2)
Spaceship.turnRight()
Spaceship.step(4)
move()
12、
def move():
Dev.step(3)
Dev.turnRight()
Dev.step(3)
Dev.turnLeft()
Spaceship.step(3)
Dev.step(-3)
Dev.step(3)
Dev.turnLeft()
Dev.step(-1)
Dev.step()
Spaceship.step(3)
Spaceship.turnRight()
move()
Spaceship.step(3)
move()
Spaceship.turnRight()
Dev.turnRight()
move()
Dev.turnRight()
Dev.step()
13、
def move():
Spaceship.step(3)
Spaceship.turnRight()
Spaceship.step(3)
Dev.step()
move()
Spaceship.step(2)
Spaceship.turnLeft()
move()
move()
Spaceship.turnRight()
Spaceship.step(2)
Spaceship.turnLeft()
Spaceship.step(3)
move()
Spaceship.step(2)
Spaceship.turnLeft()
Spaceship.step(1)
Spaceship.turnRight()
move()
14、
def move():
Dev.step(3)
for i in range(2):
Dev.turnRight()
Dev.step()
Dev.turnLeft()
Dev.step()
Dev.step()
Dev.turnLeft()
move()
Dev.turnRight()
Dev.step(2)
move()
for i in range(2):
Dev.turnRight()
Dev.step(2-3*i)
Dev.turnLeft()
Dev.step(3)
move()
Dev.step(-1)
Dev.turnRight()
Dev.step(4)
move()
15、
def move():
Dev.step(3)
Dev.turnLeft()
Dev.step(1)
Dev.turnRight()
Dev.step(-3)
move()
Flyer[0].step()
Dev.step(6)
move()
Flyer[4].step()
Dev.step(5)
Dev.turnLeft()
Dev.step(2)
move()
Flyer[2].step()
Dev.step(4)
Dev.turnLeft()
Dev.step(2)
move()
Flyer[0].step(6)
Dev.step(5)
move()
16、
def move():
for i in range(2):
Dev.step(3)
Dev.turnRight()
move()
Dev.step(4)
Dev.turnLeft()
move()
Dev.step(3)
Dev.turnLeft()
move()
Flyer[1].step(2)
Flyer[0].step(3)
Spaceship.turnRight()
Spaceship.step(3)
Dev.step(4)
Dev.turnLeft()
move()
Dev.step(2)
17、
def move():
for i in range(3):
Dev.turnRight()
Dev.step()
Dev.turnLeft()
Dev.step(-1)
Dev.step(5)
move()
Dev.turnLeft()
Dev.step(-5)
move()
Dev.turnLeft()
Dev.step(10)
move()
Dev.turnRight()
Dev.step(8)
18、
def move():
for i in range(2):
Spaceship.step(3)
Spaceship.turnRight()
Spaceship.step(3)
move()
Spaceship.turnLeft()
Spaceship.step(2)
Spaceship.turnLeft()
move()
Spaceship.step()
Spaceship.turnLeft()
move()
Spaceship.turnLeft()
Spaceship.step(2)
Spaceship.turnRight()
Spaceship.step(3)
move()
19、
def move():
for i in range(3):
if i == 2:
Spaceship.step(2)
Spaceship.turnRight()
Spaceship.step(2)
Dev.step(2)
Dev.turnRight()
Dev.step(2)
move()
Spaceship.step(3)
Spaceship.turnLeft()
Spaceship.step(3)
Dev.turnRight()
move()
Spaceship.step(4)
Spaceship.turnRight()
Spaceship.step(1)
Dev.turnLeft()
move()
20、
def move():
for i in range(2):
Dev.step(3)
Dev.turnRight()
Dev.step(2)
while Dev.energy < 100:
wait()
Dev.step()
Dev.turnLeft()
Dev.step(2)
move()
Dev.turnLeft()
Dev.step(3)
move()
Dev.step(2)
Dev.turnLeft()
Dev.step()
move()