迭失法
def factoral(n): result = n for i in range(1,n): result *= i return result number = int(input('请输入一个整数:')) print(factoral(number))
递归
def factoral(n): if n == 1: return 1 else: return n * factoral(n-1) number = int(input('请输入一个整数:')) print(factoral(number))