ICode国际青少年编程竞赛- Python-5级训练场-函数练习
1、
def get_item():
Dev.step(4) #函数内的代码,需要缩进四格
Dev.turnRight()
Dev.step(1)
Dev.step(-1)
Dev.turnLeft()
Dev.step(-4)
get_item()
Spaceship.step(4)
get_item() #可以多次调用同一个函数
Spaceship.step(5)
#尝试调用函数,继续完成后面的代码
get_item()
Spaceship.step(3)
get_item()
Spaceship.step(4)
get_item()
2、
def move():
for i in range(3):
Dev.turnRight()
Dev.step(-3)
Dev.turnRight()
move()
Dev.step(4)
move()
Dev.step(2)
move()
3、
def move():
Dev.step(4)
for i in range(3):
Dev.turnRight()
Dev.step(2)
Dev.turnRight()
Dev.step(-2)
Dev.turnRight()
Spaceship.step(2)
move()
for i in range(2):
Spaceship.step(4+i)
move()
4、
def move():
Dev.step(4)
for i in range(3):
Dev.turnLeft()
Dev.step(2)
Dev.turnLeft()
Dev.step(-2)
Spaceship.step(2)
move()
for i in range(2):
Spaceship.step(5-i)
move()
Spaceship.step(6)
move()
5、
def move():
Dev.step(4)
Dev.turnRight()
Dev.step()
Spaceship.step()
Dev.turnLeft()
Dev.step(-4)
move()
Spaceship.step(3)
move()
Spaceship.step(2)
move()
Spaceship.step(5)
move()
Spaceship.step(2)
move()
6、
def move():
Dev.step(3)
Dev.turnLeft()
Dev.step(2)
Dev.turnRight()
Spaceship.step(2)
Dev.step(-3)
Dev.turnLeft()
Spaceship.step(3)
move()
Spaceship.step()
Spaceship.turnLeft()
Dev.turnLeft()
move()
Spaceship.step(3)
move()
7、
def move():
Dev.step(3)
Dev.turnRight()
Dev.step(2)
Spaceship.step(2)
Dev.turnLeft()
Dev.step(-3)
move()
Spaceship.turnRight()
Spaceship.step()
Dev.turnRight()
move()
Spaceship.step(4)
move()
8、
def move():
for i in range(2):
Dev.step(3-i)
Dev.turnRight()
Spaceship.step(2)
Dev.step(3)
Dev.turnLeft()
Spaceship.step(2)
move()
Spaceship.turnRight()
Spaceship.step(3)
Dev.turnLeft()
move()
Spaceship.step(2)
Spaceship.turnRight()
Spaceship.step(3)
Spaceship.turnRight()
move()
9、
def move(a, b):
Dev.step(a)
Dev.turnRight()
Dev.step(-1)
Dev.turnLeft()
Dev.step(-2)
Dev.step(b)
move(3, 8)
move(0, 4)
Dev.turnLeft()
move(4, 3)
Dev.turnLeft()
move(4, 8)
move(0, 0)
10、
def move(a, b, c):
Spaceship.step(a)
for i in range(2):
Dev.step(3)
Dev.turnRight()
Spaceship.step(3)
Dev.step(3)
if c == 1:
Dev.turnLeft()
Spaceship.step(b)
Spaceship.turnRight()
move(0, 4, 1)
move(2, 0, 1)
move(2, 0, 0)
11、
def move():
Dev.turnLeft()
Dev.step(5)
for i in range(2):
Dev.step(-1)
Dev.turnLeft()
Dev.step(-1)
Dev.turnRight()
Flyer.step(2)
Dev.step(-3)
Dev.turnRight()
move()
Dev.step(3)
Flyer.step(3)
move()
Dev.step(4)
Flyer.step(4)
move()
Dev.step(2)
Flyer.step(2)
move()
Dev.step(1)
12、
def move():
Dev.turnLeft()
for i in range(3):
Dev.step(3-i)
Dev.turnRight()
Dev.step(-1)
Dev.turnLeft()
Spaceship.step(3)
Dev.step(2)
Spaceship.step()
move()
Spaceship.step(2)
Spaceship.turnRight()
move()
Spaceship.turnRight()
Spaceship.step(2)
move()
13、
def move():
for i in range(2):
Dev.step(3-i*2)
Dev.turnRight()
Dev.step(1+i)
Dev.turnLeft()
Spaceship.step(3)
Dev.step(-4)
move()
Spaceship.turnRight()
Spaceship.step(4)
Spaceship.turnLeft()
Spaceship.step(2)
move()
Spaceship.step(3)
Spaceship.turnLeft()
Spaceship.step(4)
Spaceship.turnRight()
move()
14、
def move(d):
Dev.step(d)
Dev.turnLeft()
Dev.step(3)
Dev.turnLeft()
Dev.step(1)
Dev.step(1)
Dev.turnLeft()
move(3)
for i in (1,3,0):
Dev.turnRight()
Dev.step(i)
move(4)
Dev.turnRight()
Dev.step()
Dev.turnLeft()
move(6)
Dev.step(-1)
Dev.turnRight()
Dev.step(3)
Dev.turnRight()
move(6)
15、
def move(a, b):
for i in range(2):
Dev.step((i+1)*2)
Dev.turnRight()
Dev.step(a)
Dev.step(b)
move(-1,2)
for i in range(2):
Dev.step(1+i*5)
Dev.turnLeft()
Dev.step()
Dev.turnLeft()
move(-1,2)
for i in range(2):
Dev.step(1+i*2)
Dev.turnLeft()
Dev.step(2)
move(1,-5)
Dev.turnRight()
Dev.step(3)
move(-1,2)
16、
def move():
for i in range(2):
Dev.step(2)
Dev.turnRight()
Dev.step(2)
Dev.turnLeft()
Dev.step(1)
move()
Dev.turnRight()
Dev.step(2)
move()
Dev.step(3)
Dev.turnRight()
Dev.step(2)
move()
Dev.step(1)
Dev.turnRight()
Dev.step(4)
move()
17、
def move():
for i in range(2):
Dev.step(2)
Dev.turnRight()
for i in range(2):
Dev.step(2)
Dev.turnLeft()
Dev.step(2)
for i in range(2):
Dev.step(1 + i)
move()
Dev.step(2)
Dev.turnLeft()
Dev.step(5)
move()
18、
def move():
Dev.step(4)
for i in range(4):
Dev.turnRight()
Dev.step(4-i)
Spaceship.step(2)
Dev.step(-2)
Spaceship.step()
move()
Spaceship.step(4)
Spaceship.turnRight()
Dev.turnRight()
move()
Spaceship.step(3)
Spaceship.turnRight()
Spaceship.step(1)
Dev.turnRight()
move()
19、
def move():
for i in range(4):
Dev.step(-3)
Dev.turnLeft()
Dev.step(1)
for i in range(2):
Dev.step(2)
Dev.turnLeft()
Dev.step(-1)
move()
Dev.step(1)
Dev.turnRight()
for i in range(2):
Dev.step(5)
Dev.turnRight()
Dev.step(-2)
move()
20、
def move():
for i in range(3):
Dev.step(2)
Dev.turnLeft()
Dev.step(4)
for i in range(2):
Dev.turnLeft()
Dev.step(2)
move()
Dev.step(-2)
Dev.turnLeft()
Dev.step(5)
move()
Dev.turnLeft()
Dev.step(3)
Dev.turnRight()
Dev.step(4)
move()
Dev.turnLeft()
Dev.step(2)
Dev.turnRight()
Dev.step(5)
move()