You are on page 1of 3

Que 1)

1) Draw the following pattern


1
121
12321
Ans:-
n=int(input("enter the no of rows:"))
for i in range(1,n+1):
for j in range(1,n+1-i):
print(' ',end='')
for j in range(1,i+1):
print(j,end='')
for j in range(i-1,0,-1):
print(j,end='')
print()
Output:-
enter the no of rows:3
1
121
12321

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

Ans:-

n=int(input('enter number of rows:'))

for i in range(n,0,-1):

for j in range(1,i):

print(' ', end='')


for j in range(i,i+1):

print('*', end='')

if i!=n and i!=1:

for j in range(i,n):

print(' ', end='')

for j in range(i,n-1):

print(' ', end='')

for j in range(i,i+1):

print('*', end='')

if i==1:

for j in range(i,n):

print('*', end='')

for j in range(i,n):

print('*', end='')

print()

Output:-

enter number of rows:12


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

3) Print Fibonacci series-1,2,3,5,8,13 of length 10, using any loop.


Ans:-
x=10
x1, x2=0,1
print("Fibonacci Series:",x1, x2, end=" ")
for i in range(2, x):
x3=x1+x2
x1=x2
x2=x3
print(x3, end=" ")
print()
Output:-

Fibonacci Series: 0 1 1 2 3 5 8 13 21 34

You might also like