forked from shivaylamba/Hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pascal.py
39 lines (35 loc) · 769 Bytes
/
Pascal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
n = int(input())
#pascal triangle
a=[]
for i in range(n):
a.append([])
a[i].append(1)
for j in range(1,i):
s=a[i-1][j-1]+a[i-1][j]
a[i].append(s)
a[i].append(1)
for i in range(n):
print(' '*(n-i-1),end=' ')
for j in range(0,i+1):
print(a[i][j],end=' ')
print(end='\n')
#pascal diamond
a=[]
for i in range(n):
a.append([])
a[i].append(1)
for j in range(1,i):
s=a[i-1][j-1]+a[i-1][j]
a[i].append(s)
a[i].append(1)
for i in range(n):
print(' '*(n-i-1),end=' ')
for j in range(0,i+1):
print(a[i][j],end=' ')
print(end='\n')
n=n-1
for i in range(n-1,-1,-1):
print(' '*(n-i),end=' ')
for j in range(0,i+1):
print(a[i][j],end=' ')
print(end='\n')