本题来自 Project Euler 第20题:https://projecteuler.net/problem=20

'''
Project Euler: Problem 20: Factorial digit sum
n! means n × (n − 1) × ... × 3 × 2 × 1
For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
and the sum of the digits in the number 10! is
3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.
Find the sum of the digits in the number 100!
Answer: 648
''' n = 100
fac = 1 #初始化阶乘结果
while n >= 1:
fac *= n
n -= 1 # 提取出阶乘结果的每个数字,形成列表lst
lst = [int(i) for i in str(fac)] res = 0 #初始化相加结果
for i in range(len(lst)):
res += lst[i]
print(res)

这题也容易,让先算出阶乘100的结果,然后把这结果的每个数字相加即可。

我想,应该是要练习递归阶乘吧,但我觉得用循环也挺方便的啊,就是很讨厌递归函数,总记不住写法,唉……

最新文章

  1. 时间格式转换—将后台返回的/Date(1448954018000)/格式转换为正常的时间格式
  2. sql小技巧
  3. Unicode 互转
  4. bzoj 2768: [JLOI2010]冠军调查
  5. iOS开发基础知识:Core Animation(核心动画)
  6. oracle以web方式登录EM、ISQLPlus
  7. 解决win7 中source insight没有courier new字节的问题
  8. DFT 展开式和 FFT推导
  9. U盘安装VMware ESXi 6.0
  10. public static void main(string[] args)解释
  11. python+selenium自动化软件测试(第12章):Python读写XML文档
  12. Scheme N皇后
  13. text-shadow 详解及示例
  14. lr12脚本参数化
  15. Systemd 教程
  16. BZOJ.2034.[2009国家集训队]最大收益(二分图匹配 贪心)
  17. GIT无法自动忽略YellowRV1.1.uvgui.Administrator文件的解决方法
  18. CreateProjectFormat——初始项目目录格式
  19. 软件安装的list(0918)
  20. 放弃winform的窗体吧,改用html作界面,桌面应用程序UI的新的开发方式。

热门文章

  1. 2020.08.14小bug
  2. Java自学-图形界面 Swing中的线程
  3. python实例 三国人物出场次序 jieba库
  4. 关于提高服务器的带宽策略bonding
  5. jieba分词-强大的Python 中文分词库
  6. Go语言 | goroutine不只有基础的用法,还有这些你不知道的操作
  7. 烂大街的 Spring 循环依赖问题,你觉得自己会了吗
  8. nodeJS 下载与安装,环境配置
  9. SpringBoot2 集成日志,复杂业务下的自定义实现
  10. 白嫖党看番神器 AnimeSeacher