def f(x): if x >= 1: return x*f(x-1) else: return 1 a = int(input("请输入一个数字")) print(f(a))
结果输出:
请输入一个数字5 120 Process finished with exit code 0
递归1.1使用递归实现:计算某个数的阶乘
原文:https://www.cnblogs.com/hrv5/p/11973562.html