Print Squares from 1 to N
Print each integer and its square through an entered limit. Students practice a range loop, multiplication, and f-string labels rather than a cumulative sum.
1# Take n2n = int(input("Enter n: "))34# Print squares5for i in range(1, n + 1):6 print(f"{i}² = {i * i}")
Output
Enter n: 5 1² = 1 2² = 4 3² = 9 4² = 16 5² = 25
In this one
- Compute squares per term
- Label formatted values
- Distinguish rows from totals
How it works
- 1
Visit integers from one through n.
- 2
Compute i * i for the current value.
- 3
Print its label and square on one line.
Edge cases
What happens for n = 0?
What happens for n = 0?
The loop prints no rows.
Does the superscript perform exponentiation?
Does the superscript perform exponentiation?
No. i * i computes the value.
What's going on
Each i is squared independently with i * i. The loop visits one through n because its stop is n + 1.
For n equal to three, the results are one, four, and nine on separate labelled lines. No accumulator combines them. The superscript in the label is display text; the multiplication expression performs the calculation.
What happens for n = 0? The loop prints no rows.
Does the superscript perform exponentiation? No. i * i computes the value.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
What is the square of four?
Pick an answer to check it.
Question 2
What happens for n = 0?
Pick an answer to check it.
Questions people ask
What happens for n = 0?
The loop prints no rows.
Does the superscript perform exponentiation?
No. i * i computes the value.
What is the square of four?
16.
🔗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