Founding Batch Offer ยท HLD ยท LLD ยท System Design at โ‚น799 until 30 Nov

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.

AdvancedPhase 2 - Level 5: Logical Loop CombinationsExample 7 of 12
print-i-i-pattern.py
1# Take n
2n = int(input("Enter n: "))
3
4# Print i*i pattern
5for 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. 1

    Visit one through n.

  2. 2

    Print i * i followed by a space.

  3. 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.