Python Practice Example 27

Python 100例Python 100 Examples

Title:Use recursive function calls to print the 5 entered characters in reverse order.

Program analysis:None.

Program source code:

Example (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)

Example (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)

The output result of the above example is:

Input a string:abcde
e
d
c
b
a

Python 100例Python 100 Examples

Other extensions