如何用Python循环语句制作n的阶乘
答案:2 悬赏:50 手机版
解决时间 2021-01-04 21:19
- 提问者网友:情歌越听越心酸
- 2021-01-04 04:49
如何用Python循环语句制作n的阶乘
最佳答案
- 五星知识达人网友:行路难
- 2021-01-04 05:45
from functools import reduce
from operator import mul
def jiecheng(n):
return reduce(mul, range(1, n+1))
if __name__ == '__main__':
for i in range(3, 10):
print('{}! = {}'.format(i, jiecheng(i)))wenjie@digi007:~/study/zhidao$ python3 jiecheng.py
3! = 6
4! = 24
5! = 120
6! = 720
7! = 5040
8! = 40320
9! = 362880
from operator import mul
def jiecheng(n):
return reduce(mul, range(1, n+1))
if __name__ == '__main__':
for i in range(3, 10):
print('{}! = {}'.format(i, jiecheng(i)))wenjie@digi007:~/study/zhidao$ python3 jiecheng.py
3! = 6
4! = 24
5! = 120
6! = 720
7! = 5040
8! = 40320
9! = 362880
全部回答
- 1楼网友:刀戟声无边
- 2021-01-04 07:17
def jieshen(n):
sum = 1
while sum
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯