File: pascal

package info (click to toggle)
sugar-pippy-activity 25-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 572 kB
  • ctags: 234
  • sloc: python: 1,237; makefile: 15
file content (19 lines) | stat: -rw-r--r-- 364 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Pascal's triangle
lines = 9

vector = [1]

for i in range(1,lines+1):
  vector.insert(0,0)
  vector.append(0)

for i in range(0,lines):
  newvector = vector[:]
  for j in range(0,len(vector)-1):
    if (newvector[j] == 0):
      print "  ",
    else:
      print "%2d" % newvector[j],
    newvector[j] = vector[j-1] + vector[j+1]
  print
  vector = newvector[:]