Skip to content

Commit 6e948f4

Browse files
The code generates the Pascal Triangle.
Compatible with Python 2.7.
1 parent 0115ee7 commit 6e948f4

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

other/Pascal_triangle.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Wed May 24 11:47:28 2017
4+
5+
@author: Shubham Purohit
6+
"""
7+
8+
n=input("Enter a value(>0):")
9+
10+
if n<1: # Check if number of rows > 0
11+
pass
12+
else:
13+
print [1] #print first row
14+
l=[1,1] # reference string
15+
for i in range(1,n):
16+
k=[1,1] # initialize output list
17+
for j in range(1,i):
18+
k.insert(j,(l[j-1]+l[j])) # update output list
19+
print k # print consequent rows
20+
l=k
21+
22+
23+
24+
25+

0 commit comments

Comments
 (0)