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

边栏推荐
- Kind of weird!Access the destination URL, the host can container but not
- MySQL - Multi-table query and case detailed explanation
- MySQL high-level --- storage engine, index, lock
- MySQL - 多表查询与案例详解
- MySQL Advanced Statements (1)
- MySQL 23道经典面试吊打面试官
- APP专项测试:流量测试
- C# Coding Conventions Handbook
- HCIP 第一天
- MySQL Advanced SQL Statements (2)
猜你喜欢

Wuhan 2022 organizing of the high-performance computing added new ecological development of high-performance computing

MySQL high-level --- storage engine, index, lock

解决:- SPY: No data found for this date range, symbol may be delisted报错
![[Dataset][VOC] Male and female dataset voc format 6188 sheets](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[Dataset][VOC] Male and female dataset voc format 6188 sheets

chrome 插件开发指南

MySql 5.7.38 download and installation tutorial, and realize the operation of MySql in Navicat

Detailed explanation of 9 common reasons for MySQL index failure

专家见解|经济低迷期把握创新机会的 3 大方法

chrome plugin development guide

第06章 索引的数据结构【2.索引及调优篇】【MySQL高级】
随机推荐
Py's mlxtend: a detailed guide to the introduction, installation, and usage of the mlxtend library
Connection reset by peer 问题解析
postgres 多个变量填充字符串,字串格式化
HCIP 第二天
PHP Warning: putenv() has been disabled for security reasons in phar
MySQL - 多表查询与案例详解
堡垒机、堡垒机的原理
关于ue4.27像素流送打包后的本地服务器问题
HCIP 第三天实验
Dataset: A detailed guide to the download link collection of commonly used datasets in machine learning
typescript ‘props‘ is declared but its value is never read 解决办法
文件上传漏洞(二)
rhce homework
July 18-July 31, 2022 (Ue4 video tutorials and documentation, 20 hours. Total 1412 hours, 8588 hours left)
MySQL classic 50 practice questions and the most detailed analysis of the whole network
Xgboost报错ValueError:无效的形状:标签(1650 2)
Leetcode Weekly 304
MySql 5.7.38下载安装教程 ,并实现在Navicat操作MySql
笔记本开机黑屏提示:ERROR 0199:System Security-Security password retry count exceeded
Vscode connect to remote server "Acquiring the lock on the/home / ~ 'problem