Home » Reverse Pyramid Pattern in Python

Reverse Pyramid Pattern in Python

Reverse Pyramid Pattern in Python

Hello everyone, welcome back to programminginpython.com! As a part of the series on pattern programming, Here I will explain to you how to print a reverse pyramid pattern or a reverse triangle pattern in Python. In one of my earlier posts, I have explained how to print a pyramid pattern, now I will explain how to print a reverse pyramid pattern in python.

Tip: Join Codecademy. The easiest way to learn to code. Codecademy is the easiest way to learn how to code. It’s interactive, fun, and you can do it with your friends.

Complete Python Developer Zero to Mastery – Enroll Now.

Program on Github

You can also watch the video on YouTube here.

Task

Python Program to print a Reverse Pyramid Pattern or Reverse Triangle Pattern.

Approach

  • Read an input integer for asking the range of the triangle using  input()
  • Run 3 for loops, one main for row looping, and the other 2 sub-loops for column looping, in the first loop, loop through the range of the triangle for row looping.
  • In the second loop, loop through the value of the range from max to 1, this is to print space ` `
  • In the third loop, loop through the value of range to max and print *

Print Reverse Pyramid Pattern – Code Visualization

Program

__author__ = 'Avinash'

# Print a Reverse Pyramid

# Range of the Reverse Pyramid
num = int(input("Enter the range: t "))

for rows in range(num, 0, -1):
    for columns in range(0, num-rows):
        print(end=" ")
    for columns in range(0, rows):
        print("*", end=" ")
    print()

Output

Reverse Pyramid Pattern in Python
Reverse Pyramid Pattern in Python
Reverse Pyramid Pattern in Python
Reverse Pyramid Pattern in Python

Program on Github

That is it for this tutorial. Also, feel free to look at programs on other patterns or some algorithms implementation in python here or look at all of the posts here.

Course Suggestion

The Complete Web Developer Course.
Learn Web Development by building 25 websites and mobile apps using HTML, CSS, Javascript, PHP, Python, MySQL & more!
Course: The Complete Web Developer Course 2.0

Find more on pattern programming below,

Online Python Compiler

Leave a Reply

Your email address will not be published. Required fields are marked *