当前位置:网站首页>实例027:递归输出
实例027:递归输出
2022-08-02 06:16:00 【懒笑翻】
题目:利用递归函数调用方式,将所输入的5个字符,以相反顺序打印出来。
解题:
"""
学习中遇到问题没人解答?小编创建了一个Python学习交流QQ群,可扫文末的推广进群哦
寻找有志同道合的小伙伴,互帮互助,群里还有不错的视频学习教程和PDF电子书!
"""
# 利用递归函数调用方式,将所输入的5个字符,以相反顺序打印出来。
def rec(string):
if len(string) != 1: # 长度不为1时一直递归调用
print(string[1:]) # 输出看每次递归调用时传入的值
rec(string[1:])
print(string[0], end='') # 输出第一个长度
str = input('请输入长度为5的字符串:')
if len(str) > 5:
print("请输入长度为5的字符串")
else:
rec(str)结果:

边栏推荐
- Revitalize rural circular economy and digital chain to link agricultural "ecological chain"
- Connection reset by peer 问题解析
- 【21天学习挑战赛】顺序查找
- MySQL - Multi-table query and case detailed explanation
- [21天学习挑战赛——内核笔记](一)——设备树的概述(硬件、目标、效果、文件类型)
- MySQL driver jar package download -- nanny tutorial
- In-depth analysis of the initialization of member variables and local variables
- Go inside the basic knowledge
- (笔记整理未完成)【图论】图的遍历
- MySQL union query (multi-table query)
猜你喜欢

数据库概论之MySQL表的增删改查2

Revitalize rural circular economy and digital chain to link agricultural "ecological chain"

MySql 5.7.38下载安装教程 ,并实现在Navicat操作MySql

HCIP 第三天实验

Clapper that can interact with the audience in real time

PMP新考纲通关秘籍,告别抓瞎

APP special test: traffic test

MySQL - Multi-table query and case detailed explanation

武汉高性能计算大会2022举办,高性能计算生态发展再添新动力

Nodejs installation and global configuration (super detailed)
随机推荐
C# FileInfo类
Nodejs installation tutorial
ASP.NET Core Web API 幂等性
Detailed explanation of 9 common reasons for MySQL index failure
Nodejs安装教程
有点奇怪!访问目的网址,主机能容器却不行
Technology empowers Lhasa's "lungs", Huawei helps Lalu Wetland Smart Management to protect lucid waters and lush mountains
MySQL union query (multi-table query)
数据库概论之MySQL表的增删改查1
node安装及环境变量配置
享年94岁,图灵奖得主、计算复杂性理论先驱Juris Hartmanis逝世
[数据集][VOC]男女数据集voc格式6188张
MySQL classic 50 practice questions and the most detailed analysis of the whole network
[21天学习挑战赛——内核笔记](一)——设备树的概述(硬件、目标、效果、文件类型)
(笔记整理未完成)【图论】图的遍历
技术管理三级跳
aTrust项目的相关操作与分享
The nacos source code can not find the istio package
专家见解|经济低迷期把握创新机会的 3 大方法
abaqus如何快速导入其他cae文件的assembly?