Real-Time Example Program of Nested Loop

Question 1 - Print numbers in increasing order

for i in range(1, 6):
    print()
    for j in range(1, i+1):
        print(j, end = "")

Output

1
12
123
1234
12345

Question 2 - Print stars in increasing pattern

for i in range(1, 6):
    print()
    for j in range(1, i+i):
        print("*", end = "")

Output

*
***
*****
*******
*********

Post a Comment

0 Comments