programming-examples/python/Math/Calculate the difference between the squared sum and the sum of squared of first n natural numbers.py

13 lines
313 B
Python
Raw Normal View History

2019-11-15 12:59:38 +01:00
def sum_difference(n=2):
sum_of_squares = 0
square_of_sum = 0
for num in range(1, n+1):
sum_of_squares += num * num
square_of_sum += num
square_of_sum = square_of_sum ** 2
return square_of_sum - sum_of_squares
print(sum_difference(12))