Pascal Triangle Pattern in Python

Pascal triangle program in python using for loop. python programming language Pascal pattern program. The pascal pattern program is printed in the output of this program. This pattern program is very similar to python’s pascal program.

line = 5
for i in range(0, line):
for j in range(0, i + 1):
print("*", end=' ')
print("\r")
for i in range(line, 0, -1):
for j in range(0, i - 1):
print("*", end=' ')
print("\r")

 

Output:

*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*

range() Method in Python

The range() method in Python creates an immutable series of integers starting with the supplied start integer and ending with the specified finish integer. It’s a built-in function that returns a range object made up of a sequence of integer integers that we may loop over. We can use a range to make creating a for loop easier (). The range() function must have a fixed finish value, but we may vary the start ing value and the step between integers.

For Loop in Python

For loops in Python are often used in data science work to loop through an iterable object and perform the same operation on each item. A for loop, for example, would allow us to go over a list and perform the same operation on each item. The for loop in Python is used to iterate over a sequence that might be a list, tuple, array, or string. The init step is the initial one, and it is only performed once. During this stage, you can declare and initialise any loop control variables.