当前位置:网站首页>实例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)结果:

边栏推荐
- Toolbox App 1.25 New Features at a Glance | Version Update
- MySql 5.7.38下载安装教程 ,并实现在Navicat操作MySql
- Leetcode Weekly 304
- MySQL Advanced Statements (1)
- Toolbox App 1.25 新功能一览 | 版本更新
- Ant three sides: MQ message loss, duplication, backlog problem, what are the solutions?
- pointer arithmetic in c language
- Vscode connect to remote server "Acquiring the lock on the/home / ~ 'problem
- SphereEx苗立尧:云原生架构下的Database Mesh研发实践
- CAT1 4G+Ethernet development board Tencent cloud mobile phone WeChat applet display temperature and delivery control
猜你喜欢

The stock price has repeatedly hit new lows, and the real estate SaaS giant is in trouble. How should Mingyuan Cloud transform and save itself?

MySQL classic 50 practice questions and the most detailed analysis of the whole network

第06章 索引的数据结构【2.索引及调优篇】【MySQL高级】

推出 Space On-Premises (本地部署版) Beta 版!

PMP新考纲考试内容介绍

实验7 MPLS实验

Specified URL is not reachable,caused by :‘Read timed out

optional

chrome 插件开发指南

Unity Shader学习(七)纹理图像的简单使用
随机推荐
MPLS的相关技术
In-depth analysis of the initialization of member variables and local variables
【21天学习挑战赛】顺序查找
看图就懂|衡量业务增长健康的销售指标如何选择
MySQL 5.7 installation tutorial (full-step, nanny-level tutorial)
nacos源码启动找不到istio包
HCIP 第二天
.NET Static Code Weaving - Rougamo Release 1.1.0
C# FileInfo类
交换网络----三种生成树协议
aTrust项目的相关操作与分享
How does abaqus quickly import the assembly of other cae files?
2022年7月18日-7月31日(Ue4视频教程和文档,20小时。合计1412小时,剩8588小时)
宝塔+FastAdmin 404 Not Found
Py之mlxtend:mlxtend库的简介、安装、使用方法之详细攻略
2022年8月计划,着重ue4视频教程
MySQL 23道经典面试吊打面试官
享年94岁,图灵奖得主、计算复杂性理论先驱Juris Hartmanis逝世
DNS resolution process
数据库概论-MySQL的数据表的基本操作