ICode国际青少年编程竞赛- Python-5级训练场-函数练习2
1、
def get_item(a):
Spaceship.step(1)
Dev.step(a)
Dev.turnLeft()
Dev.step(1)
Spaceship.step(1)
Dev.turnRight()
Dev.step(-a)
Spaceship.step(1)
get_item(3)
get_item(2)
get_item(3)
get_item(1)
get_item(5)
2、
def get_item(a):
Dev.step(1)
for i in range(4):
Dev.step(a)
Dev.turnRight()
Dev.step(-1)
Dev.step(1)
get_item(2)
Spaceship.step(5)
get_item(4)
Spaceship.step(6)
get_item(3)
Spaceship.step(6)
get_item(1)
3、
def get_item(a):
Dev.step(1)
Flyer[a].step(1)
for i in range(4):
Dev.step(2)
Dev.turnLeft()
Dev.step(-1)
get_item(1)
for i in range(2):
Dev.turnRight()
Spaceship.step(2)
get_item(2)
Spaceship.step(2)
Spaceship.turnRight()
Spaceship.step(2)
for i in range(2):
Dev.turnRight()
get_item(0)
4、
def move(ok,a):
Dev.step(1*ok)
for i in range(4):
Dev.step(a*ok)
if ok == 1:
Dev.turnRight()
if ok == -1:
Dev.turnLeft()
Dev.step(-1*ok)
move(1, 2)
Spaceship.step()
Spaceship.turnRight()
Spaceship.step(2)
move(-1, 4)
Spaceship.turnLeft()
Spaceship.step(4)
move(1, 1)
Spaceship.step(3)
Spaceship.turnRight()
Spaceship.step()
move(-1, 3)
for i in range(2):
Spaceship.turnLeft()
Spaceship.step(2-i)
move(1, 5)
5、
def move(a, b, c):
Spaceship.step(a)
Dev.step(2)
for i in range(2):
Dev.step(b)
Dev.turnLeft()
Dev.step(c)
Dev.turnLeft()
Dev.step(-2)
Dev.turnRight()
move(0, 2, 2)
move(4, 4, 2)
move(5, 7, 2)
6、
def move(a):
Dev.step(a)
Dev.turnRight()
Dev.step(a-1)
Dev.turnLeft()
Spaceship.step(a-1)
Dev.step(-a)
move(3)
Spaceship.turnRight()
Spaceship.step(2)
Spaceship.turnLeft()
Spaceship.step(2)
move(5)
Spaceship.step(2)
Spaceship.turnLeft()
Spaceship.step(2)
Spaceship.turnRight()
move(4)
Spaceship.turnRight()
Spaceship.step(2)
Spaceship.turnLeft()
Spaceship.step(2)
move(3)
7、
def get_items(a,b):
Dev.step(a)
Dev.turnRight()
Dev.step(b)
Dev.turnLeft()
Spaceship.step(b)
Dev.step(-a)
get_items(4,2)
Spaceship.step(2)
Spaceship.turnLeft()
Spaceship.step(2)
Spaceship.turnRight()
get_items(3,4)
Spaceship.turnRight()
Spaceship.step(4)
Spaceship.turnLeft()
Spaceship.step(2)
get_items(6,3)
Spaceship.step(2)
Spaceship.turnLeft()
Spaceship.step(3)
Spaceship.turnRight()
get_items(4,1)
8、
def move(a, b, c):
Spaceship.step(a)
Dev.step(b)
Dev.turnRight()
Dev.step(c)
Dev.turnLeft()
Spaceship.step(c)
Dev.step(-b)
Dev.turnLeft()
move(1, 5, 3)
move(2, 4, 1)
move(2, 6, 2)
move(2, 2, 1)
move(2, 3, 2)
9、
def move(a, b, c):
Spaceship.step(a)
Dev.step(2)
for i in range(2):
Dev.step(b)
Dev.turnRight()
Dev.step(c)
Dev.turnRight()
Dev.step(-2)
move(0, 3, 2)
move(4, 6, 3)
move(6, 5, 2)
move(4, 2, 3)
10、
Dev.turnLeft()
def move(a, b, c):
Spaceship.step(a)
Dev.step(2)
for i in range(2):
Dev.step(b)
Dev.turnRight()
Dev.step(c)
Dev.turnRight()
Dev.step(-2)
move(1, 2, 2)
move(4, 4, 1)
move(3, 6, 4)
move(6, 1, 1)
11、
def move(a):
for i in range(4):
Flyer[a+i].step()
Dev.step()
for i in range(4):
Dev.step(4)
Dev.turnRight()
Dev.step(-1)
move(4)
for i in range(2):
Spaceship.turnRight()
Spaceship.step(4-i)
Dev.turnRight()
move(8)
Spaceship.step()
Spaceship.turnRight()
Spaceship.step(5)
for i in range(2):
Dev.turnRight()
move(0)
12、
def move(a, b, c, d):
if a == 5:
Spaceship.turnRight()
Spaceship.step(a)
if a == 2:
Spaceship.turnRight()
if a != 2:
Spaceship.turnLeft()
Spaceship.step(b)
Dev.step(-1)
for i in range(2):
Dev.step(c)
Dev.turnRight()
Dev.step(d)
Dev.turnRight()
Dev.step(1)
move(2, 1, -2, -2)
move(4, 6, -1, -1)
move(5, 3, -3, -2)
13、
def move(a, b, c):
Dev.step(a)
for i in range(2):
Dev.step(b)
Dev.turnRight()
Dev.step(c)
Dev.turnRight()
Dev.step(-a)
Dev.turnLeft()
move(1, 3, 3)
Spaceship.step(4)
move(-1, -5, -4)
Spaceship.step(1)
Dev.turnRight()
move(1, 3, 6)
Spaceship.turnLeft()
Spaceship.step(1)
Dev.turnLeft()
move(1, 2, 4)
14、
def move(a, b):
Flyer[a].step(b)
Dev.step(3)
Spaceship.step(2)
for i in range(2):
Dev.turnRight()
Dev.step(2 + i)
move(0, 3)
Dev.turnLeft()
Spaceship.turnRight()
Spaceship.step()
move(2, 4)
Dev.turnLeft()
Spaceship.step(1)
Spaceship.turnRight()
move(1, 1)
15、
def move(a, b):
for i in range(a):
Dev.step(b)
Dev.turnLeft()
Dev.step(-b)
if i == 1 and b == 3:
Dev.step(-1)
if i == 3 and b == 1:
Dev.step(-2)
Dev.turnRight()
move(2, 2)
Dev.step(3)
move(2, 3)
Dev.step(2)
Dev.turnRight()
Dev.step(1)
move(4, 1)
Dev.step(-2)
Dev.turnRight()
Dev.step()
move(4, 2)
16、
def move(a, b, c):
Spaceship.step(a)
Dev.step(c)
for i in range(4):
Dev.step(b)
Dev.turnRight()
Dev.step(-c)
move(0, 3, 5)
move(6, 2, 3)
move(4, 4, 3)
move(6, 2, 6)
17、
def move(a, b, c, d):
for i in range(4):
Flyer[a+i].step(d)
Dev.step(c)
for i in range(4):
Dev.step(b)
Dev.turnRight()
Dev.step(-c)
move(0, 4, 1, 1)
Spaceship.turnRight()
Spaceship.step()
Spaceship.turnLeft()
Spaceship.step(8)
move(4, -4, -1, 2)
Spaceship.turnLeft()
Spaceship.step(2)
move(8, 4, 1, 3)
18、
def move(a, b, c, d):
Spaceship.step(a)
Dev.step(b)
Dev.step(c)
Dev.turnLeft()
Dev.step(-2)
Dev.turnRight()
Spaceship.step(2)
Dev.step(d)
move(0, 5, -2, -3)
move(2, 3, -1, -2)
move(4, 6, -4, -2)
move(3, 5, -1, -4)
19、
def f(a,b,c, d):
Spaceship.step(d)
Dev.step(a)
Dev.turnLeft()
for i in range(2):
Dev.step(b)
Dev.turnRight()
Dev.step(c)
Dev.turnRight()
Dev.step(b)
Dev.turnRight()
Dev.step(-a)
f(5, 1, 2, 0)
f(7, 2, 3, 5)
f(6, 1, 3, 5)
f(10, 2, 3, 4)
20、
def move(a, b, c, d):
Dev.step(b)
for i in range(4):
Flyer[a+i].step(d)
for i in range(4):
Dev.step(c)
Dev.turnRight()
Dev.step(-b)
move(0, 1, 6, 2)
for i in range(2):
Spaceship.step(3)
Spaceship.turnRight()
move(8, -1, -4, 1)
for i in (1, 3):
Spaceship.turnRight()
Spaceship.step(i)
Dev.turnRight()
move(4, 1, 2, 1)