aboutsummaryrefslogtreecommitdiff
path: root/challenge-003/paulo-custodio/python/ch-2.py
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2021-01-28 00:33:56 +0000
committerPaulo Custodio <pauloscustodio@gmail.com>2021-01-28 00:33:56 +0000
commite233d3a019dda275d8d790076d25ec92e47b4ffe (patch)
tree48516daf26833baca8695204a4d83c81d58a6dd7 /challenge-003/paulo-custodio/python/ch-2.py
parent022a9f62eda3b5e188b9f6719a63566d9d7efc8b (diff)
downloadperlweeklychallenge-club-e233d3a019dda275d8d790076d25ec92e47b4ffe.tar.gz
perlweeklychallenge-club-e233d3a019dda275d8d790076d25ec92e47b4ffe.tar.bz2
perlweeklychallenge-club-e233d3a019dda275d8d790076d25ec92e47b4ffe.zip
Add Basic, C, C++, Forth, Lua and Python to challenge 003
Diffstat (limited to 'challenge-003/paulo-custodio/python/ch-2.py')
-rw-r--r--challenge-003/paulo-custodio/python/ch-2.py26
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]))