Print i*i Pattern
Print a row of integer squares using Python. Students trace a one-line sequence, multiplication before output, and a newline separate from the number loop.
1# Take n2n = int(input("Enter n: "))34# Print i*i pattern5for i in range(1, n + 1):6 print(i * i, end=" ")7print()
Output
Enter n: 5 1 4 9 16 25
In this one
- Generate square values
- Keep one-line output
- End a spaced sequence
How it works
- 1
Visit one through n.
- 2
Print i * i followed by a space.
- 3
Finish the line after the loop.
Edge cases
What if n = 0?
What if n = 0?
Only the final newline is printed.
Is i * i exponentiation by XOR?
Is i * i exponentiation by XOR?
No. It is ordinary multiplication; ^ would mean XOR.
What's going on
The loop visits one through n and prints i * i each time. No original-value labels or running sum are included in this version.
end leaves a space after each square, allowing all values to share a line. The final empty print ends that line. For n equal to four, the numeric contents are 1 4 9 16, not the total thirty.
What if n = 0? Only the final newline is printed.
Is i * i exponentiation by XOR? No. It is ordinary multiplication; ^ would mean XOR.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
What is the fourth printed value?
Pick an answer to check it.
Question 2
What if n = 0?
Pick an answer to check it.
Questions people ask
What if n = 0?
Only the final newline is printed.
Is i * i exponentiation by XOR?
No. It is ordinary multiplication; ^ would mean XOR.
What is the fourth printed value?
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