python3练习100题——027

又是一道迭代的题,没做好。

看了答案才试着写出来。 我一定要加油啊,为了尽快摆脱现在讨厌的生活!

原题链接:http://www.runoob.com/python/python-exercise-example27.html

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

我的代码:

a = input("please input a string:")

def fun(s,l):
    if l==0:
        return
    else:
        print (s[l-1])
        fun(s,l-1)        #再调用一遍函数,用于迭代!

fun(a,len(a))
原文地址:https://www.cnblogs.com/drifter/p/9186170.html