Hollow Pyramid Pattern in PythonIn this tutorial, we will learn how to create different types of hollow pyramid patterns using Python. Program 1: Program to make a simple hollow pyramid in Python Code: Output: Explanation: This hollow pyramid pattern can be made with any symbol like * or #. We have made this hollow pyramid using nested loops with the character '*'. We have printed 2 * r - 1 (r is the number of rows in the pattern) '*' characters in the last row. The number of rows can also be changed. This hollow pyramid can be made using another method using for loops and elif conditions: Method 2: Code: Output: Explanation: This hollow pyramid pattern is similar to the above one, but the pattern's formation process differs. We have used elif statements to print the character '*' in the hollow pyramid. We can make this basic hollow pyramid pattern using only while function also. Code: Output: Explanation: This hollow pyramid is made using while loops. In this, the user takes the number of rows as input. It is a short and simple method to print the basic hollow pyramid. There can be various patterns and modifications of the hollow pyramid. Modifications of the hollow pyramid1. Left half pyramidCode: Output: Explanation: We have made a left-side half pyramid using loops. The user will give the number of rows as input. 2. Left downward half pyramidCode: Output: Explanation: We have made a left-side downward hollow pyramid. In this, a reverse loop prints the downward left-side pyramid. 3. Downward Hollow PyramidCode: Output: Explanation: We have made a downward hollow pyramid in which the number of rows decreases in the loop. We have made various types of hollow pyramid patterns using Python. Next TopicJSON Schema Validator Python |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India