Sum of Squares Up to N

Calculate sum of squares from 1² to n².

Logic BuildingBeginner
Logic Building
# Take n as input
n = int(input("Enter n: "))

# Calculate sum of squares
sum_squares = 0
for i in range(1, n + 1):
    sum_squares += i * i

print(f"Sum of squares: {sum_squares}")

Output

Enter n: 5
Sum of squares: 55

Square each number and add to sum.

Key Concepts:

  • Loop from 1 to n
  • Calculate i * i for each
  • Accumulate sum