小练习---反向打印字符串

  • 利用递归函数调用方式,将所输入的5个字符,以相反顺序打印出来。
1 def output(s,l):
2     if l==0:
3         return
4     print(s[l-1])
5     output(s,l-1)
6 s = input('Input a string:')
7 l = len(s)
8 output(s,l)
1 Input a string:abcdef
2 f
3 e
4 d
5 c
6 b
7 a

猜你喜欢

转载自www.cnblogs.com/monsterhy123/p/12575185.html