ICode国际青少年编程竞赛- Python-6级训练场-递归入门

2024-05-13 15:12

本文主要是介绍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级训练场-递归入门的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/986062

相关文章

Conda与Python venv虚拟环境的区别与使用方法详解

《Conda与Pythonvenv虚拟环境的区别与使用方法详解》随着Python社区的成长,虚拟环境的概念和技术也在不断发展,:本文主要介绍Conda与Pythonvenv虚拟环境的区别与使用... 目录前言一、Conda 与 python venv 的核心区别1. Conda 的特点2. Python v

Python使用python-can实现合并BLF文件

《Python使用python-can实现合并BLF文件》python-can库是Python生态中专注于CAN总线通信与数据处理的强大工具,本文将使用python-can为BLF文件合并提供高效灵活... 目录一、python-can 库:CAN 数据处理的利器二、BLF 文件合并核心代码解析1. 基础合

Python使用OpenCV实现获取视频时长的小工具

《Python使用OpenCV实现获取视频时长的小工具》在处理视频数据时,获取视频的时长是一项常见且基础的需求,本文将详细介绍如何使用Python和OpenCV获取视频时长,并对每一行代码进行深入解析... 目录一、代码实现二、代码解析1. 导入 OpenCV 库2. 定义获取视频时长的函数3. 打开视频文

Python中你不知道的gzip高级用法分享

《Python中你不知道的gzip高级用法分享》在当今大数据时代,数据存储和传输成本已成为每个开发者必须考虑的问题,Python内置的gzip模块提供了一种简单高效的解决方案,下面小编就来和大家详细讲... 目录前言:为什么数据压缩如此重要1. gzip 模块基础介绍2. 基本压缩与解压缩操作2.1 压缩文

Python设置Cookie永不超时的详细指南

《Python设置Cookie永不超时的详细指南》Cookie是一种存储在用户浏览器中的小型数据片段,用于记录用户的登录状态、偏好设置等信息,下面小编就来和大家详细讲讲Python如何设置Cookie... 目录一、Cookie的作用与重要性二、Cookie过期的原因三、实现Cookie永不超时的方法(一)

Python内置函数之classmethod函数使用详解

《Python内置函数之classmethod函数使用详解》:本文主要介绍Python内置函数之classmethod函数使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录1. 类方法定义与基本语法2. 类方法 vs 实例方法 vs 静态方法3. 核心特性与用法(1编程客

从入门到精通MySQL联合查询

《从入门到精通MySQL联合查询》:本文主要介绍从入门到精通MySQL联合查询,本文通过实例代码给大家介绍的非常详细,需要的朋友可以参考下... 目录摘要1. 多表联合查询时mysql内部原理2. 内连接3. 外连接4. 自连接5. 子查询6. 合并查询7. 插入查询结果摘要前面我们学习了数据库设计时要满

Python函数作用域示例详解

《Python函数作用域示例详解》本文介绍了Python中的LEGB作用域规则,详细解析了变量查找的四个层级,通过具体代码示例,展示了各层级的变量访问规则和特性,对python函数作用域相关知识感兴趣... 目录一、LEGB 规则二、作用域实例2.1 局部作用域(Local)2.2 闭包作用域(Enclos

Python实现对阿里云OSS对象存储的操作详解

《Python实现对阿里云OSS对象存储的操作详解》这篇文章主要为大家详细介绍了Python实现对阿里云OSS对象存储的操作相关知识,包括连接,上传,下载,列举等功能,感兴趣的小伙伴可以了解下... 目录一、直接使用代码二、详细使用1. 环境准备2. 初始化配置3. bucket配置创建4. 文件上传到os

使用Python实现可恢复式多线程下载器

《使用Python实现可恢复式多线程下载器》在数字时代,大文件下载已成为日常操作,本文将手把手教你用Python打造专业级下载器,实现断点续传,多线程加速,速度限制等功能,感兴趣的小伙伴可以了解下... 目录一、智能续传:从崩溃边缘抢救进度二、多线程加速:榨干网络带宽三、速度控制:做网络的好邻居四、终端交互