Sum of squares of positive integers less than or equal to n

This problem asks the reader to write a Python function that calculates the sum of the squares of all positive integers less than or equal to a given integer n. An example input and output are provided .

Problem

Write a Python function that takes an integer n and returns the sum of the squares of all the positive integers less than or equal to n.
Example input:
n = 5
Example output:
55

Solution

This solution is in Python. Our A.I. can create solutions in multiple languages.
by kayakane
def sum_of_squares(n):
    return sum([i**2 for i in range(n+1)])

print(sum_of_squares(5))

A.I. Evaluation of the Solution

This solution is complete and solves the problem. The approach is to use a list comprehension to square each number in the range from 0 to n, inclusive, and then sum the resulting list.

Evaluated at: 2022-11-18 04:15:55