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 [1]:
def squares(number_of_numbers): # this function takes an input of how many "natural numbers" you want, in this case "100"
sqrd_sum = []
sumd = 0
for i in range(number_of_numbers): # i ranges from 0-9
sqrd_sum.append((i + 1) ** 2) # appends 1 squared to 10 squared to "sqrd_sum"
sumd = i + 1 + sumd # since i goes from 1-9, this creates the sum of the values 1-10
sumd = sumd ** 2 # this squares the sum of the number 1-10
return (sumd - sum(sqrd_sum)) # and then the difference between the sum of squares and the square of the sum
print(squares(100))
In [ ]:
# This cell will be used for grading, leave it at the end of the notebook.