The problem you are going to solve is the following Compute
Solution
Solution:
# recursive method to compute the factorial of a number
def recfactorial(n):
if n == 1:
return n
else:
return n*recfactorial(n-1)
# method to compute sum of factorial and find sum divisible by 7
def sumdiv7(n):
# list to store sum
factlist=[]
# loop to compute factorial
for i in range(1,n+1):
sum=0
for j in range(1,i+1):
sum=sum+recfactorial(j)
if i>2:
sum=sum+1
factlist.append(sum)
print \"The sum of factorial is\", factlist
# filter to find a sum value divisible by 7
result=filter(lambda x:x%7==0,factlist)
print \"The sum divisible by 7 is\",result
Result:
>>> sumdiv7(5)
The sum of factorial is [1, 3, 10, 34, 154]
The sum divisible by 7 is [154]
