原题:
原题解答:
#!/usr/bin/python # encoding=utf-8 # -*- coding: UTF-8 -*- # 利用递归函数调用方式,将所输入的5个字符,以相反顺序打印出来。 #str = input() """ def printStr(j): if str: s = printStr(j) s = j[-1] j = j[:-1] else : s = None return printStr(j) print(printStr(str)) """ def output(s,l): if l == 0 : return print(s[l-1]) output(s,l-1) s = input("please input the str:\n") l = len(s) output(s,l)
输出结果:
————————(我是分割线)————————
参考:
1. RUNOOB.COM:https://www.runoob.com/python/python-exercise-example27.html
备注:
初次编辑时间:2019年10月4日11:01:46
环境:Windows 7 / Python 3.7.2