https://projecteuler.net/problem=6
The sum of the squares of the first ten natural numbers is,
$$1^2 + 2^2 + ... + 10^2 = 385$$The square of the sum of the first ten natural numbers is,
$$(1 + 2 + ... + 10)^2 = 552 = 3025$$Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.
In [24]:
#create a function to compute the sum of squares
def sum_of_squares(limit):
#assign variables
total = 0
answer = range(0,limit+1)
#as answer variable creates list, create a running sum of each number squared
for number in answer:
total += number**2
return total
#create a function to create the square of sum
def square_of_sum(limit):
#assign variables
answer = range(0,limit+1)
total = sum(answer)
#return the square of the running sum
return total**2
print (square_of_sum(10) - sum_of_squares(10))
In [21]:
# This cell will be used for grading, leave it at the end of the notebook.