Nested Loop Programs Baby Level
Nested Loop Programs Baby Level
Q1. Write a program to print the multiplication table of all numbers from 2 to 5
Code:
for i in range(2, 6):
for j in range(1, 11):
print(f"{i} x {j} = {i*j}")
print()
Output:
2 x 1 = 2
...
2 x 10 = 20
3 x 1 = 3
...
5 x 10 = 50
Code:
for i in range(1, 5):
print('*' * i)
Output:
*
**
***
****
Code:
for i in range(1, 5):
for j in range(1, i+1):
print(j, end='')
print()
Output:
1
12
123
1234
Code:
for i in range(4, 0, -1):
for j in range(1, i+1):
print(j, end='')
print()
Output:
1234
123
12
1
Code:
for i in range(4, 0, -1):
for j in range(i, 0, -1):
print(j, end='')
print()
Output:
4321
321
21
1
Code:
for i in range(1, 5):
print(str(i) * i)
Output:
1
22
333
4444
Code:
for i in range(4, 0, -1):
print(str(i) * i)
Output:
4444
333
22
1
Output:
1
21
321
4321
Code:
for i in range(4):
print(str(2**i) * (i+1))
Output:
1
22
444
8888
Code:
for i in range(1, 4):
for j in range(65, 65+i):
print(chr(j), end='')
print()
Output:
A
AB
ABC
Code:
for i in range(1, 4):
for j in range(65, 65+i):
print(chr(j), end='')
print()
Output:
A
AB
ABC
Q12. Print pattern:1121123211234321
Code:
for i in range(1, 5):
for j in range(1, i+1):
print(j, end='')
for j in range(i-1, 0, -1):
print(j, end='')
print()
Output:
1
121
12321
1234321