本题来自 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的结果,然后把这结果的每个数字相加即可。

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

Python练习题 047:Project Euler 020:阶乘结果各数字之和的更多相关文章

  1. Python练习题 028:求3*3矩阵对角线数字之和

    [Python练习题 028] 求一个3*3矩阵对角线元素之和 ----------------------------------------------------- 这题解倒是解出来了,但总觉得 ...

  2. Python练习题 036:Project Euler 008:1000位数字中相邻13个数字最大的乘积

    本题来自 Project Euler 第8题:https://projecteuler.net/problem=8 # Project Euler: Problem 8: Largest produc ...

  3. Python练习题 021:递归方法求阶乘

    [Python练习题 021] 利用递归方法求5!. ---------------------------------------------- 首先得弄清楚:5! 指的是"5的阶乘&qu ...

  4. Python练习题 022:用递归函数反转字符串

    [Python练习题 022] 利用递归函数调用方式,将所输入的5个字符,以相反顺序打印出来. --------------------------------------- 又来一个递归题!不过,有 ...

  5. Python练习题 032:Project Euler 004:最大的回文积

    本题来自 Project Euler 第4题:https://projecteuler.net/problem=4 # Project Euler: Problem 4: Largest palind ...

  6. Python练习题 029:Project Euler 001:3和5的倍数

    开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...

  7. Python练习题 046:Project Euler 019:每月1日是星期天

    本题来自 Project Euler 第19题:https://projecteuler.net/problem=19 ''' How many Sundays fell on the first o ...

  8. Python练习题 043:Project Euler 015:方格路径

    本题来自 Project Euler 第15题:https://projecteuler.net/problem=15 ''' Project Euler: Problem 15: Lattice p ...

  9. Python练习题 039:Project Euler 011:网格中4个数字的最大乘积

    本题来自 Project Euler 第11题:https://projecteuler.net/problem=11 # Project Euler: Problem 10: Largest pro ...

随机推荐

  1. 使用Apache的反向代理会影响搜索引擎的收录和排名吗

    http://www.wocaoseo.com/thread-292-1-1.html 百度官方观点:Baiduspider对站点的抓取方式和普通用户访问一样,只要普通用户能访问到的内容,我们就能抓取 ...

  2. 力扣Leetcode 461. 汉明距离

    给你一个数组 arr ,请你将每个元素用它右边最大的元素替换,如果是最后一个元素,用 -1 替换. 完成所有替换操作后,请你返回这个数组. 示例: 输入:arr = [17,18,5,4,6,1] 输 ...

  3. 关于华为服务器 双路E52620安装系统时遇到的问题

    一   准备好u盘启动盘,centos7的,用UltraISO制作启动盘 双击图标 进入 点击启动下的刻录磁盘映像 几分钟之后制作完场 二 :按装centos7的系统 1 首先将 u盘插到服务器上 2 ...

  4. day41:MYSQL:select查询练习题

    目录 1.表结构 2.创建表和插入数据 3.习题 1.表结构 2.建表和插入数据 # 创建班级表 create table class( cid int primary key auto_increm ...

  5. Laravel Facade原理及使用

    Laravel Facade原理及使用 laravel过于庞大,加之笔者水平有限,所以后面的源码解读会按模块功能介绍,希望能帮大家稍微捋顺下思路,即使能够帮助大家回顾几个函数也好.如发现错误,还望指正 ...

  6. GENYMOTION问题之an error occurred while deploying a file install_failed_no_machine_abis

    GENYMOTION问题之an error occurred while deploying a file install_failed_no_machine_abis 出现上面错误,看网上有一种解决 ...

  7. android开发之动画的详解 整理资料 Android开发程序小冰整理

    /** * 作者:David Zheng on 2015/11/7 15:38 * *  网站:http://www.93sec.cc * *  微博:http://weibo.com/mcxiaob ...

  8. vue 组件内的守卫

    1.beforeRouteEnter ()  // 进入该组件之前要去进行的逻辑操作, 2.beforeRouteLeave() // 离开该组件之前要去进行的逻辑操作(可清除定时器等耗用内存的变量, ...

  9. SpringCloud系列之Nacos+Dubbo应用篇

    目录 前言 项目版本 项目说明 项目结构 集成Dubbo2.6.x 支付模块 用户模块 集成Dubbo2.7.x 支付模块 用户模块 测试验证 参考资料 系列文章 前言 本文在前篇文章<Spri ...

  10. java初探(1)之登录初解

    初识登录 登录的应用场景 登录比较常见,大多数网站都有登录的操作.然后登录本身也从简单到复杂有着漫长的发展历史.本文记录博主对登录的应用场景的剖析,深究不在于学习如何实现,主要关注其编码思想,过程中用 ...