利用递归函数计算阶乘
用户输入一个数,计算这个数的阶乘: 比如:5! = 120
class Factorial: def fact(self,num): if num > 0: return num*self.fact(num-1) else: return 1 num = float(input('输入要求的阶乘:')) a = Factorial() ret = a.fact(num) print(ret)
class Factorial: def fact(self,num): if num > 0: return num*self.fact(num-1) else: return 1 num = float(input('输入要求的阶乘:')) a = Factorial() ret = a.fact(num) print(ret)