Python Practice (vii) calculates the and of the factorial of 1 to N

Source: Internet
Author: User


Factorial:

All the product of a positive integer less than and equal to the number, when n is 5 o'clock, the factorial of 5 is 5!=1*2*3*4*5=120



The factorial of 0 is always equal to 1.

The factorial of 1 equals 1*1 1.

The factorial of 2 equals 1*1*2 2.

The factorial of 3 equals 1*1*2*3 6.

The factorial of 4 equals 1*1*2*3*4 24.

The factorial of 5 equals 1*1*2*3*4*5 120.


For example, calculate the factorial of 5 with the following code:

n = 5sum = 1for i in range (1, n + 1): Sum *= iprint (sum)



Calculate the factorial of 1 to 5 and the code is as follows:

n = 5sum = 1total = 0for i in range (1, n+1): #1, 2,3,4,5 sum *= i total + = Sumprint


Control of the value boundary of n

Sum represents the value of the factorial of each number

Sum of total totals




Python Practice (vii) calculates the and of the factorial of 1 to N

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.