python题目-求阶乘

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/test_soy/article/details/88025259

题目;

输入任意一个数字计算阶乘

a = int(input('请任意输入一个数字的阶乘'))
b = 1

if a < 0:
    print('负数没有阶乘!')
elif a == 0:
    print('0的阶乘固定为1!')
else:
    for i in range(1,a+1):
        b = b * i
    print('%s 的阶乘为 %s' % (a,b))

猜你喜欢

转载自blog.csdn.net/test_soy/article/details/88025259
今日推荐