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