CoursesCSS StudioExamplesGATECompaniesPrepMentora
Programs/Logic building/Phase 2 - Level 1: Basic Looping

13 / 14

Next
1. Print Numbers from 1 to 102. Print All Even Numbers Between 1 and 1003. Sum of First N Natural Numbers4. Print the Factorial of a Given Number5. Print All Odd Numbers Between 1 and 1006. Print Numbers from 10 Down to 17. Print Multiplication Table8. Sum of All Even Numbers Up to N9. Sum of All Odd Numbers Up to N10. Product of Digits11. Count Numbers Divisible by 312. Print Multiples of 5 Up to N13. Sum of Squares Up to N14. Print Alternating Numbers

Phase 2 - Level 1: Basic Looping

  1. 01Print Numbers from 1 to 10
  2. 02Print All Even Numbers Between 1 and 100
  3. 03Sum of First N Natural Numbers
  4. 04Print the Factorial of a Given Number
  5. 05Print All Odd Numbers Between 1 and 100
  6. 06Print Numbers from 10 Down to 1
  7. 07Print Multiplication Table
  8. 08Sum of All Even Numbers Up to N
  9. 09Sum of All Odd Numbers Up to N
  10. 10Product of Digits
  11. 11Count Numbers Divisible by 3
  12. 12Print Multiples of 5 Up to N
  13. 13Sum of Squares Up to N
  14. 14Print Alternating Numbers

Sum of Squares Up to N

Calculate sum of squares from 1² to n².

BeginnerPhase 2 - Level 1: Basic LoopingExample 13 of 14
sum-of-squares-up-to-n.py
1# Take n as input
2n = int(input("Enter n: "))
3
4# Calculate sum of squares
5sum_squares = 0
6for i in range(1, n + 1):
7 sum_squares += i * i
8
9print(f"Sum of squares: {sum_squares}")

Output

Enter n: 5
Sum of squares: 55

What's going on

Square each number and add to sum.

Key Concepts:

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

🔗Related Content

  • 📖

    Phase 2 - Learn Concepts

    Review Phase 2 concepts and explanations

  • 📝

    Phase 2 - Quiz

    Test your Phase 2 understanding with quiz questions

  • 💻

    Phase 2 - All Practice Problems

    Explore all practice problems for Phase 2

  • 🎓

    Master Your Logic Building - Complete Course

    Browse all phases and tutorials

  • 🧠

    Logic Building Overview

    Learn about the complete logic building curriculum

PreviousPrint Multiples of 5 Up to NNextPrint Alternating Numbers

On this page

CodeOutputExplanation
Up nextPrint Alternating Numbers
Schoolabe

Learn, Practice, Ace Coding

ExamplesCompaniesTutorialsCSS StudioDSA VisualizersQuizInterview PrepMentoraCareer QuestGATE CS prepGATE CS 2027 study planJob ReadyInternships
AboutContactCareersAffiliate programBlog
DocumentationAPI ReferenceCommunitySupport
Privacy PolicyTermsRefund PolicyCookie Policy

© 2026 Schoolabe