Write Python script to calculate sum of following series :
s = (1) + (1+2) + (1+2+3) +…+ (1+2+3+…+n)
Answers
Answered by
0
The python script to calculate the given series is:
def SeriesSum ( n ):
return sum ( [x*(x+1)/2 for x in range(1, n + 1) ] )
- After specifying the "n" one can calculate the sum.
- In the program, a function is defined named "SeriesSum".
- The function is having the parameter "n".
- After that, the sum is returned using list comprehension.
Similar questions
Geography,
5 months ago
Computer Science,
5 months ago
Math,
5 months ago
Computer Science,
11 months ago
Computer Science,
11 months ago
Physics,
1 year ago