Q. Python program to print differrent pattern triangle.

For loop is a versatile tool in python it can be used print Differrent pattern in python.
Down below two differrent codes are written to print the same kind of pattern.

In this code, n=6 intialised used as refrence and mark the number of rows. In 2nd line we have for loop "i" which will be executed 6 times, then we have two nested for loops in first loops we are printing spaces which goes from (0 to (n-i-1)) e.g (6-0-1 = 5 ) , so that means 5 spaces will be printed on first row and when that is executed 2nd nested loop will come into play which is responsible for printing "#" first row -> " #" 2nd row -> " ##" as value of i increases spaces will be decreasing and number of "#" will be increasing with each row.

code-1 to print traingle

OR

different way to print triangle

Output
output of triangle

Related Post


How to insert a element in linked list python?

A linked list is a sequence of data elements, which are connected together via links. Each data element contains a connection to another data element.....


finding the Two sum from list which is equal to the target value ?

a list is created by placing elements inside square brackets [], separated by commas. a list can have any number of items............

Finding the middle element from a linked list Python?

A linked list is a sequence of data elements, which are connected together via links. Each data element contains a connection to another........

Q.how to Reverse a linked list python ?

To Reverse a linked a list , we iterate over each element and store it in a list and then iterate over th...