阶乘小程序

def fun(num):
    sum = 1
    if num > 1:

        sum = num * (num - 1)
        num = num - 1
        sum = sum * ( num - 1 )
        fun(num-1)
    return sum
while True:
    num = input('输入一个数>>').strip()
    if num.isdigit():
        res  = fun(int(num))
        print(res)
        break
    else:
        print('请重新输入')

 

posted on 2019-01-21 15:02  小胖子方法  阅读(181)  评论(0编辑  收藏  举报

导航