Loop Practice Question - III ( DS150423 )

Write a program to achieve below pattern :

1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
1 Like

for i in range(1, 5):   # outer loop for rows
    for j in range(1, 5):   # inner loop for columns
        print(i, end=" ")   # print the value of i with a space
    print()   # move to the next line after printing each row

3 Likes
for i in range(1,5):
    for j in range(1,5):
        print(i,end=" ")
    print()

Screenshot (344)

2 Likes

1 Like
start_parameter = int(input('Enter rhe start range parameter:    '))
end_parameter = int(input('Enter rhe end range parameter:    '))

for i in range(start_parameter, end_parameter+1):
    for j in range(end_parameter):
        print(i, end = ' ')
    print()
1 Like
for i in range (1,5): # Executing rows
    for j in range(1,5): # Executing column
        print(i, end=" ") # printing outcomes with spaces
    print()   # shift to the next line  after getting the outcome

image

1 Like

1 Like

image

1 Like

1 Like

for i in range(1, 5): # First loop to print the row numbers
for j in range(4): # Second loop to print the column values
print(i, end=’ ')
print() # Move to the next line after each row is printed

for i in range(1, 5): # loop through each row
for j in range(1, 5): # loop through each column in the current row
print(i, end=" ") # print the current row number, followed by a space
print() # move to the next line after each row

n=4
for i in range(1,n+1):
print((str(i)+’ ')*n)