Python 练习实例27

简介: Python 练习实例27

题目:利用递归函数调用方式,将所输入的5个字符,以相反顺序打印出来。

程序分析:无。

程序源代码:

实例(Python 2.0+)

#!/usr/bin/python# -*- coding: UTF-8 -*- def output(s,l):     if l==0:        return    print (s[l-1])    output(s,l-1) s = raw_input('Input a string:')l = len(s)output(s,l)

实例(Python 3.0+)

#!/usr/bin/python3 def output(s,l):     if l==0:        return    print (s[l-1])    output(s,l-1) s = input('Input a string:')l = len(s)output(s,l)

以上实例输出结果为:

Input a string:abcde

e

d

c

b

a

相关文章
|
3天前
|
Python
Python 练习实例94
Python 练习实例94
|
3天前
|
Python
Python 练习实例92
Python 练习实例92
|
3天前
|
Python
Python 练习实例93
Python 练习实例93
|
2天前
|
Python
Python 练习实例97
Python 练习实例97
|
2天前
|
Python
Python 练习实例96
Python 练习实例96
|
4天前
|
Python
Python 练习实例90
Python 练习实例90
|
4天前
|
数据安全/隐私保护 Python
Python 练习实例89
Python 练习实例89
|
4天前
|
Python
Python 练习实例91
Python 练习实例91
|
2天前
|
Python
Python 练习实例95
Python 练习实例95
|
3天前
|
Python
Python中类属性与实例属性的区别
了解这些区别对于编写高效、易维护的Python代码至关重要。正确地使用类属性和实例属性不仅能帮助我们更好地组织代码,还能提高代码运行的效率。
6 0