KEMBAR78
Chapter 04a. Pattern Programs | PDF
0% found this document useful (0 votes)
14 views5 pages

Chapter 04a. Pattern Programs

The document provides various Python pattern programs that demonstrate how to print different shapes using asterisks and other characters. It includes examples for printing rows of asterisks, square patterns, right-angle triangles, pyramids, inverted pyramids, and diamond shapes. Each pattern is accompanied by sample code and expected output based on user input for the number of rows or symbols.

Uploaded by

gentleman.asyu
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)
14 views5 pages

Chapter 04a. Pattern Programs

The document provides various Python pattern programs that demonstrate how to print different shapes using asterisks and other characters. It includes examples for printing rows of asterisks, square patterns, right-angle triangles, pyramids, inverted pyramids, and diamond shapes. Each pattern is accompanied by sample code and expected output based on user input for the number of rows or symbols.

Uploaded by

gentleman.asyu
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/ 5

Python 3x

Python Pattern Programs

1
Pattern-1: To print given number of *s in a row
test.py

1) n=int(input('Enter n value:'))
2) for i in range(n):
3) print('*',end=' ')

Output:
Enter n value:5
*****

Pattern-2: To print square pattern with * symbols


test.py

1) n=int(input('Enter No Of Rows:'))
2) for i in range(n):
3) print('* '*n)

Output:
Enter No Of Rows:5
*****
*****
*****
*****
*****

Pattern-3: To print square pattern with provided fixed digit in every row
test.py

1) n=int(input('Enter No Of Rows:'))
2) for i in range(n):
3) print((str(i+1)+' ')*n)

2
Output:
Enter No Of Rows:5
11111
22222
33333
44444
55555

Pattern-4: To print square pattern with alphabet symbols


test.py

1) n=int(input('Enter No Of Rows:'))
2) for i in range(n):
3) print((chr(65+i)+' ')*n)

Output:
Enter No Of Rows:5
AAAAA
BBBBB
CCCCC
DDDDD
EEEEE

Pattern-5: To print Right Angle Triangle pattern with * symbols


test.py

1) n=int(input('Enter No Of Rows:'))
2) for i in range(n):
3) for j in range(i+1):
4) print('*',end=' ')
5) print()

Output:
Enter No Of Rows:5
*
**
***

3
****

Pattern-6: To print Inverted Right Angle Triangle pattern with * symbols


test.py

1) n=int(input('Enter No Of Rows:'))
2) for i in range(n):
3) print('* '*(n-i))

Output:
Enter No Of Rows:5
*****
****
***
**
*

Pattern-7: To print Pyramid pattern with * symbols


test.py

1) n=int(input('Enter Number of rows:'))


2) for i in range(n):# 0,1,2,3
3) print((' '*(n-i-1))+ ('* ')*(i+1))

Output:
Enter number of rows:5
*
**
***
****
*****

4
Pattern-8: To print Inverted Pyramid Pattern with * symbols
test.py

1) n=int(input('Enter Number of Rows:'))


2) for i in range(n): #0,1,2,3
3) print(' '*i+'* '*(n-i))

Output:
Enter Number of Rows:5
*****
****
***
**
*

Pattern-9: To print Diamond Pattern with * symbols


test.py

1) n=int(input('Enter n Value:'))
2) for i in range(n):#0,1,2,3
3) print(' '*(n-i-1)+'* '*(i+1))
4) for i in range(n-1):#0,1,2
5) print(' '*(i+1)+'* '*(n-i-1))

Output:
Enter n Value:5
*
**
***
****
*****
****
***
**
*

You might also like