Python Online Compiler
Example: Pascal Triangle Pattern in Python language using loop
C
C++
C#
Java
Python
PHP
main.py
STDIN
Run
# Pascal Triangle Pattern in Python language using loop r, co, ws, i, j = None, 1, None, None, None # r - denotes the number of rows # co - denotes the coefficient value # ws - denotes the white space print ("-----Enter the number of rows to print the pattern-----") r = int (input ()) print ("\n-----This is the pascal triangle pattern-----\n") for i in range (r): print (end="\t") for ws in range (1, (r + 1) - i): print (end=" ") for j in range (i + 1): if j == 0 or i == 0: co = 1 else: co = co * (i - j + 1) / j print (end="%4d" %(co)) print (end="\n")
7
Output
Clear
ADVERTISEMENTS