Python Pyramid Pattern Program
Introduction
Patterns can be printed in python using simple for loops. The first outer loop is used to handle the number of rows and the inner nested loop is used to handle the number of columns. Manipulating the print statements, different numbers patterns, alphabet patterns, or star patterns can be printed.
Some of the Patterns are:
Simple Half Pyramid Pattern
Example Code:
Output:
Explanation:
- In the above program, we are using nested for loop, and the required variables should be declared and initialized.
- We get the value from the user to print the number of rows.
- The first ‘for’ loop starts from i=0 to i=number.
- The inner for loop starts from j=0 to j=i+1.
- The given symbol is printed for the given number of rows.
Simple Full Pyramid Pattern
Example code:
Output:
Approach 2: Using List in Python 3:
Example Code:
Output:
Approach 3: Using recursion
Example code:
Output:
Approach 4: Using a while loop
Example Code:
Output:
Approach 5:Using a for loop:
Number Pattern
Example code:
Output:
Numbers without reassigning:
Example code:
Output:
Character Pattern
Example code:
Output:
Continuous Character Pattern
Example code:
Output:
Conclusion
Once we get the logic of the program, we can print any pattern using the Python loops.
Mark Lesson Complete (Python Pyramid Pattern Program)
Mark Complete
Bookmark