用python写1到5的阶乘程序
以下是用Python编写1到5的阶乘程序的代码:
# 计算1到5的阶乘
for i in range(1, 6):
result = 1
for j in range(1, i+1):
result *= j
print(i, "的阶乘为:", result)
输出结果:
1 的阶乘为: 1
2 的阶乘为: 2
3 的阶乘为: 6
4 的阶乘为: 24
5 的阶乘为: 120
原文地址: http://www.cveoy.top/t/topic/htIg 著作权归作者所有。请勿转载和采集!