本文主要是介绍ICode国际青少年编程竞赛- Python-6级训练场-递归入门,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
ICode国际青少年编程竞赛- Python-6级训练场-递归入门
1、
def recur(n):# 边界条件if n<1:return# 额外动作Dev.step(n)Dev.turnRight()# 递归调用recur(n-1)recur(8)
2、
def recur(n):# 边界条件if n<1:return# 额外动作Dev.step(n)Dev.turnLeft()# 递归调用recur(n-1)
recur(8)
3、
def recur(n):# base case if n < 3:return# actionsSpaceship.step(2)Spaceship.turnLeft()Spaceship.step(n)Spaceship.turnLeft()Spaceship.turnLeft()Spaceship.step(n)Spaceship.turnLeft()# recursionrecur(n-1)recur(7)
4、
def recur(n):# base case if n < 0:return# actionsSpaceship.step(3)Spaceship.turnLeft()Spaceship.step(5-n)Spaceship.turnLeft()Spaceship.turnLeft()Spaceship.step(5-n)Spaceship.turnLeft()# recursionrecur(n-1)recur(3)
5、
def recur(n):# Complete the base case if n < 2: return# actionsSpaceship.step(2)Spaceship.turnLeft()Spaceship.step(n)Spaceship.turnLeft()Spaceship.turnLeft()Spaceship.step(8)Spaceship.turnLeft()Spaceship.turnLeft()Spaceship.step(8-n)Spaceship.turnRight()# recursionrecur(n-1)recur(6)
6、
def recur(n):# Base caseif n < 1:return# fill in the actionsDev.step(2)Dev.turnRight()Dev.step(2)Dev.turnLeft()# recursionrecur(n-1)recur(8)
7、
def recur(n):# Base caseif n < 0: return# actionsFlyer[n].step(1)# recursionrecur(n-1)
recur(6)
Dev.step(8)
8、
def recur(n):# Complete the codeif n > 6: returnFlyer[n].step(7-n)recur(n+1)
recur(0)
Dev.step(14)
9、
def recur(n):# Base caseif n < 1:return# Finish the actionsFlyer.step(2)Dev.turnRight()Dev.step(2)Dev.step(-2)Dev.turnLeft()Dev.step(2)# recursionrecur(n - 1)recur(6)
10、
def recur(n):if n < 0: returnSpaceship.step(2)Dev.step(n)Dev.step(-2*n)Dev.step(n)recur(n-2)
Dev.turnRight()
recur(8)
11、
def recur(n):# base case and recursionif n < 1: returnFlyer[7-n].step()recur(n-1)# actionsrecur(6)
Dev.step(7)
12、
def recur(n):# base caseif n > 7: return# actionsFlyer[7-n].step()# recursionrecur(n+1)
recur(0)
Dev.step(9)
13、
def recur(n):# base caseif n > 3:return# actionsSpaceship.step(n+1)Flyer[n].step(5-n)Dev.step(n+2)Dev.step(-n-2)# recursionrecur(n+1)
recur(0)
14、
def recur(n):Dev.step(2)if n>0:recur(n-1)Flyer.step(2)Dev.turnLeft()Dev.step(2)Dev.step(-2)Dev.turnRight()Dev.step(-2)
recur(5)
15、
def recur(n):# base caseif n < 6: return# actionsDev.step(n)Dev.step(3-n)Dev.turnLeft()recur(n-1)# recursionrecur(9)
16、
def get(a):if a < 1:returnDev.turnLeft()Dev.step(a)Dev.turnRight()Dev.step(a)Dev.step(-a)Dev.turnRight()Dev.step(a*2)Dev.turnLeft()Dev.step(a)get(a-1)
get(4)
17、
def move(a):if a < 1: returnDev.turnRight()Dev.step(a)Dev.turnLeft()Dev.step(a)Dev.step(-a)Dev.turnRight()Dev.step(-2*a)Dev.turnLeft()Dev.step(3)move(a-1)
move(4)
18、
def move(a):if a < 2: returnDev.step(a)Dev.turnLeft()Dev.step()Dev.step(-1)Dev.turnRight()Dev.step(-a)Dev.turnLeft()Dev.step(a/2)Dev.turnRight()move(a-2)
move(10)
19、
def move(a):if a < 1: returnSpaceship.step(a)Spaceship.turnRight()Spaceship.turnRight()Spaceship.step(2*a)Spaceship.turnLeft()Spaceship.step(a)Spaceship.turnLeft()move(a-1)
move(4)
20、
def move(a):if a > 5: returnSpaceship.step(a)Spaceship.turnLeft()Spaceship.step(a)Dev.step(a-1)Dev.step(1-a)Dev.turnLeft()Dev.step(a)Dev.turnRight()Dev.step(a)Dev.step(-a)Dev.turnLeft()Dev.step(-a)Dev.turnRight()Spaceship.turnRight()move(a+1)
move(2)
这篇关于ICode国际青少年编程竞赛- Python-6级训练场-递归入门的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!