Latest web development tutorials

Python includes exercises 27

Python 100 Li Python 100 Li

Title: recursive function call, five characters are entered, printed out in reverse order.

Program Analysis: None.

Source Code:

#!/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)

The above example output is:

Input a string:abcde
e
d
c
b
a

Python 100 Li Python 100 Li