第4章-25.求1!+3!+5!+……+n! (10分)

求1!+3!+5!+……+n!的和,要求用循环嵌套设计,n<12。

输入格式:

输入在一行中给出一个不超过12的正整数n。

输出格式:

在一行中按照格式“n=n值,s=阶乘和”的顺序输出,其中阶乘和是正整数。

输入样例:

5
 

输出样例:

n=5,s=127
 1 # 求1!+3!+5!+……+n!
 2 # Author: cnRick
 3 # Time  : 2020-3-31
 4 n = int(input())
 5 result = 0
 6 for num in range(1,n+1,2):
 7     eachResult = 1
 8     for i in range(1,num+1):
 9         eachResult *= i
10     result += eachResult
11 print("n={:d},s={:d}".format(n,result))
 
原文地址:https://www.cnblogs.com/dreamcoding/p/12606115.html