Python Exercise Example 27
**Problem:** Use recursive function calls to print the 5 input characters in reverse order.
**Analysis:** None.
Program source code:
Example (Python 2.0+)
#!/usr/bin/python
-- coding: UTF-8 --
def
output
(
s
,
l
)
:
if
l
==
0
:
return
(
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
(
s
[
l
1
]
)
output
(
s
,
l
1
)
s
=
input
(
'
Input a string:
'
)
l
=
len
(
s
)
output
(
s
,
l
)
The output of the above example is:
Input a string:abcde
e
d
c
b
a
Python 100 Examples