table of Contents
Getting Quick Python includes exercises
Getting Quick Python includes exercises
Title: seeking 1 + 2 +3 + ... + N and!!!.
Program analysis:
This is the meaning of factorial, a math symbol means from 1 multiplied by 2 multiplied by 3 multiplied by 4 to take up "!" Before the number.
1! It refers to the factorial of 1, 1! = 1;
2! It refers to the factorial of 2, 2! = 1 × 2 = 2;
3! It refers to the factorial of 3, 3! = 1 × 2 × 3 = 6;
And so on.
Any natural number n is greater than 1 represents the factorial method:! N = 1 × 2 × 3 × ...... × n.
n=1 #乘数
sum=1 #总和
for i in range(1,9): #第几个数字
while n<=i:
sum=sum*n #累×
n=n+1
print(sum)
X=int(input('请输入阶乘数字:'))
n=1 #乘数
s=1
sum=0 #总和
for i in range(1,X+1): #第几个数字
while n<=i:
s=s*n #累×
n=n+1
sum=sum+s
print(sum)