Computer Science, asked by Mister360, 3 months ago

3 3 3 3
4 4 4 4
5 5 5 5
6 6 6 6


programme the above output

Use=Python

Note:-

Use only 1 loop​

Answers

Answered by anindyaadhikari13
6

Answer:

There are different approaches for solving this question.

1. Using 1 loop. (Counter)

i,a,c=1,3,0

while i<=4:

print(a,end=" ")

c+=1

if c>3:

 c,a,i=0,a+1,i+1

 print()

2. Using 1 loop. (String multiplication)

for i in range(3,7):

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

3. One liner c∅de. (Using joín() function)

print("\n".joín((str(i)+" ")*4 for i in range(3,7)))

Note: It would be better if this problem is solved using string multiplication. Just iterate a loop within the range 3 to 6, convert the loop variable into string, multiply the string with 4 (so that the string gets repeated 4 times) and display it.

Refer to the attachment.

•••♪

Attachments:
Similar questions