CS Practical File Question
Q. Generate the following pattern using nested loop.
*
* *
* * *
* * * *
* * * * *
Ans. for i in range(1,6): #outer
loop
for j in range(1,i+1):
#inner loop
print('*',end='
')
print()
Q. Generate the following pattern using nested loop.
A
A B
A B C
A B C D
A B C D E
Ans.
for i in range(1,6): #outer loop
for j in range(1,i+1): #inner
loop
if j==1:
j='A'
elif j==2:
j='B'
elif j==3:
j='C'
elif j==4:
j='D'
else:
j='E'
print(j,end=' ')
print()
Comments
Post a Comment