Page Contents
- 1 Pyramid Pattern Program In Python that most asked in Interview
- 1.1 And below Python concepts are used to print that patterns
- 1.2 1). Program to print half pyramid pattern using star(*) in Python
- 1.3 2). Program to print inverted half pyramid pattern using star(*) in Python
- 1.4 3). Program to print right half pyramid pattern using star(*) in Python
- 1.5 4). Program to print inverted right half pyramid pattern using star(*) in Python
- 1.6 5). Program to print full pyramid pattern using star(*) in Python
- 1.7 6). Program to print inverted full pyramid pattern using star(*) in Python
- 1.8 7). Program to print half pyramid pattern using numbers in Python
- 1.9 8). Program to print inverted half pyramid pattern using numbers in Python
- 1.10 Also prepare these Python Pattern Programs:
- 1.11 Also prepare these Python Programs:
Interview Content
- C Programming Coding Questions
- C Pattern Programming Questions
- C Programming Interview Questions
- Java Programming Coding Questions
- Java Pattern Programming Questions
- Java Programming Interview Questions
- Python Programming Coding Questions
- Python Pattern Programming Questions
- Python Programming Interview Questions
- SQL Interview Questions
Pyramid Pattern Program In Python that most asked in Interview
Ans:
And below Python concepts are used to print that patterns
- For Loop
- While Loop
- if..else
1). Program to print half pyramid pattern using star(*) in Python
n = int(input("Enter the number of rows for half pyramid:"))
for i in range(0, n):
for j in range(0, i+1):
print('*',end='')
print()
Output
2). Program to print inverted half pyramid pattern using star(*) in Python
n = int(input("Enter the number of rows for half pyramid:"))
for i in range(n,0, -1):
for j in range(i, 0,-1):
print('*',end='')
print()
Output
3). Program to print right half pyramid pattern using star(*) in Python
n = int(input("Enter the number of rows for half pyramid:"))
k = n-1
for i in range(0, n):
for j in range(0, k):
print(end=" ") #Here, take two spaces.
k = k - 1
for j in range(0, i+1):
print("*",end='')
print()
Output
4). Program to print inverted right half pyramid pattern using star(*) in Python
n = int(input("Enter the no. of rows for Inv. half pyramid:"))
k = 0
for i in range(n, 0, -1):
for j in range(0, k):
print(end=" ")
k = k + 1
for j in range(i, 0,-1):
print("*",end='')
print()
Output
5). Program to print full pyramid pattern using star(*) in Python
n = int(input("Enter the number of rows for pyramid:"))
k = n-1
for i in range(0, n):
for j in range(0, k):
print(end=" ")
k = k - 1
for j in range(0, i+1):
print("* ",end='')
print()
Output
6). Program to print inverted full pyramid pattern using star(*) in Python
n = int(input("Enter rows for Inv. Full Pyramid Pattern:"))
k = 0
for i in range(n, 0, -1):
for j in range(0, k):
print(end=" ")
k = k + 1
for j in range(i, 0,-1):
print("*",end='')
for j in range(i, 1,-1):
print("*",end='')
print()
Output
7). Program to print half pyramid pattern using numbers in Python
n = int(input("Enter no. of rows for half pyramid:"))
for i in range(0, n):
value = 1
for j in range(0, i+1):
print(value,end=" ")
value = value + 1
print()
Output
8). Program to print inverted half pyramid pattern using numbers in Python
n = int(input("Enter no. of rows for half pyramid:"))
for i in range(n, 0, -1):
value = 1
for j in range(i+1, 1, -1):
print(value,end=" ")
value = value + 1
print()
Output
Also prepare these Python Pattern Programs:
Also prepare these Python Programs:
- Write a program to reverse an integer in Python.
- Write a program in Python to check whether an integer is Armstrong number or not.
- Python Program to check a given number is Prime number or not.
- Write a program in Python to print the Fibonacci series using iterative method.
- Write a program in Python to print the Fibonacci series using recursive method.
Latest Uploads on Website
- AVL Tree with explanation
- Radix sort algorithm explanation with example
- Quick Sort Algorithm with explanation
- Bubble sorting algorithm with Bubble sort program in C
- Insertion sort algorithm and program in C
- Selection Sort Algorithm and Program in C
- Linear probing technique explanation with example
- Collision in Hashing and Collision resolution technique
- Hashing in data structure with its types
- Binary search tree operations with Program
- Binary search tree in data structure
- Binary search algorithm in data structure with explanation
- linear search in data structure with Algo and Program