0% found this document useful (0 votes)
6 views

Alok Raj (216301012) 3.2 Python Assignment

I am boy

Uploaded by

216301012
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Alok Raj (216301012) 3.2 Python Assignment

I am boy

Uploaded by

216301012
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Pattern 2.

1 - Inverted Triangle
Code:-
rows = int(input("Enter number of rows: "))
for i in range(rows, 0, -1):
for j in range(0, i):
print("* ", end=" ")
print("\n")

output:-
***
**
*

Pattern 2.2 -Reversed Pattern

Code:-
N=int(input("Enter number of rows : "))
row=1;
while row<=N:
col=1;
while col<=N:
if(col<=N-row):
print(" ",end="")
else:
print("*",end="")
col=col+1
row=row+1
print(" ")

output:-
*
**
***

Pattern 2.1 -Isosceles Pattern

Code:-
N=int(input("Enter Number of Rows : "))
row=1;
while row<=N:
spaces =1
while spaces<= N- row:
print(" ",end="")
spaces=spaces+1

num=1
while num<=row:
print(num,end="")
num=num+1;

num=row-1
while num>=1:
print(num,end="")
num=num-1
print()
row=row+1

output:-

1
121
12321
1234321
Practice Problem
Code:-1

N=int(input("Enter No. :"))


row=1
while (row<=N):
col=1
space=1
while (space<=N-row):
print(" ",end="")
space=space+1
while (col<=2*row-1):
print("*",end="")
col=col+1
row=row+1
print()

output:-
code:-2
N=int(input("Enter No. :"))
row=1
while (row<=N):

for space in range(1,N-row+1):


print(" ",end="")
space=space+1
for num in range(1,row+1) :
print(num,end="")
num=num+1
for num in range(row-1,0,-1):
print(num,end="")
num=num-1
row=row+1
print()
row=1
while (row<N):
for space in range(1,row+1):
print(" ",end="")
space=space+1
for num in range(1,N-row+1) :
print(num,end="")
num=num+1
for num in range(N-row-1,0,-1):
print(num,end="")
num=num-1
row=row+1
print( )

output:-
code:-3
N=int(input("Enter No. :"))
row=1
while (row<=N):

for space in range(1,row):


print(" ",end="")
print(row,end="")
for space in range(1,2*N-2*row):
print(" ",end="")
if(row!=N):
print(row,end="")
row=row+1
print()
row=1
while (row<N):
for space in range(1,N-row):
print(" ",end="")
print(N-row,end="")
for space in range(1,2*row):
print(" ",end="")
if(row!=N):
print(N-row,end="")
row=row+1
print()

output:-

code:-4

N=int(input("Enter No. :"))


row=1
while (row<=N):

for space in range(1,N-row+1):


print(" ",end="")
for i in range(1,2*row) :
print("*",end="")
row=row+1
print()
row=1
while (row<N):
for space in range(1,row+1):
print(" ",end="")
for i in range(N-2*row+3,0,-1) :
print("*",end="")
row=row+1
print( )

output:-

You might also like