Print the following pattern using Looping statements. In python
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Answers
Answered by
1
Answer:
rows = input("Enter the number of rows: ")
# Outer loop will print the number of rows.
for i in range(0, rows):
# This inner loop will print the stars.
for j in range(0, i + 1):
print("*", end=' ')
# Change line after
Answered by
5
Required Answer:-
Question:
Python program to display the following pattern.
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Solution:
Here is the code.
for i in range(1,6):
for j in range(1,i+1):
print(j,end=" ")
print()
Dry Run:
When i = 1:
Inner loop will run from 1 to 1.
Output: 1
When i = 2:
Inner loop will run from 1 to 2.
Output: 1 2
When i = 3:
Inner loop will run from 1 to 3
Output: 1 2 3
When i = 4:
Inner loop will run from 1 to 4.
Output: 1 2 3 4
When i = 5:
Inner loop will run from 1 to 5.
Output: 1 2 3 4 5
Hence, the final result is,
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Output is attached.
Attachments:
Similar questions