diff options
Diffstat (limited to 'challenge-003/paulo-custodio/python/ch-2.py')
| -rw-r--r-- | challenge-003/paulo-custodio/python/ch-2.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/challenge-003/paulo-custodio/python/ch-2.py b/challenge-003/paulo-custodio/python/ch-2.py new file mode 100644 index 0000000000..d97750c634 --- /dev/null +++ b/challenge-003/paulo-custodio/python/ch-2.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python + +# Challenge 003 +# +# Challenge #2 +# Create a script that generates Pascal Triangle. Accept number of rows from +# the command line. The Pascal Triangle should have at least 3 rows. For more +# information about Pascal Triangle, check this wikipedia page. + +import sys + +def draw_pascal(rows): + data = [1] + for row in range(1,rows+1): + # print current row + print(" "*(rows-row) + " ".join([str(x) for x in data])) + + # compute next row + nxt = [1] + for col in range(0, len(data)-1): + nxt.append(data[col] + data[col+1]) + nxt.append(1) + data = nxt + +# main +draw_pascal(int(sys.argv[1])) |
