Math, asked by Mister360, 4 months ago

Print :-

1 1 1 1
2 2 2 2
3 3 3 3
Language :- Python

Answers

Answered by anindyaadhikari13
15

Answer:

There are different approaches for solving this pattern in Python.

1. Using nested loop (General Method).

for i in range(1,4):

for j in range(4):

print(i,end=" ")

print()

2. Using 1 loop (Concept of string multiplication)

for i in range(1,4):

print((str(i)+" ")*4)

3. One line c∅de (advanced)

print(*[(str(i)+" ")*4 for i in range(1,4)],sep="\n")

Logic:

  • Iterate outer loop in range 1 to 3.
  • Iterate inner loop 4 times.
  • Display the value of the outer loop variable with a space.
  • Print a new line after displaying each row.

Refer to the attachment.

•••♪

Attachments:
Similar questions