Python Exercises 047:project Euler 020: The sum of the numbers of factorial results

Source: Internet
Author: User

Topic from Project Euler 20th: https://projecteuler.net/problem=20

"Project euler:problem 20:factorial Digit sumn! means NX (n? 1) x...x3x2x1for example, 10! = 10x9x...x3x2x1 = 3628800,and The sum of the digits in the number 10! IS3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.Find The sum of the digits in the number 100!  answer:648 "n = 100FAC = 1  #初始化阶乘结果while n >= 1:    FAC *= n n = #    extract each number of factorial results, form a list lstlst = [Int (i) for I In STR (FAC)]res = 0  #初始化相加结果for i in range (len (LST)):    res + = Lst[i]print (res)

The problem is also easy, starters figure out the result of factorial 100, and then add each number of the results.

I think, should be to practice the recursive factorial, but I think the loop is also very convenient ah, is very annoying recursive function, always remember the wording, alas ...

Python Exercises 047:project Euler 020: The sum of the numbers of factorial results

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.