aboutsummaryrefslogtreecommitdiff
path: root/challenge-031/paulo-custodio/python
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-12-23 13:31:49 +0000
committerGitHub <noreply@github.com>2021-12-23 13:31:49 +0000
commit41c63ddc2a230fde6dcc037c8d89027b9a6caa09 (patch)
tree38f3cd47311fda3f846237a46c2f10288ba91323 /challenge-031/paulo-custodio/python
parentc124588bfd1e7cb271c5d5f36c5e7ef87d934121 (diff)
parentc4bb1dec1a1fb2c69ce19643f4442e9139613d3b (diff)
downloadperlweeklychallenge-club-41c63ddc2a230fde6dcc037c8d89027b9a6caa09.tar.gz
perlweeklychallenge-club-41c63ddc2a230fde6dcc037c8d89027b9a6caa09.tar.bz2
perlweeklychallenge-club-41c63ddc2a230fde6dcc037c8d89027b9a6caa09.zip
Merge pull request #5406 from pauloscustodio/devel
Devel
Diffstat (limited to 'challenge-031/paulo-custodio/python')
-rw-r--r--challenge-031/paulo-custodio/python/ch-1.py18
-rw-r--r--challenge-031/paulo-custodio/python/ch-2.py13
2 files changed, 31 insertions, 0 deletions
diff --git a/challenge-031/paulo-custodio/python/ch-1.py b/challenge-031/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..6d380fde03
--- /dev/null
+++ b/challenge-031/paulo-custodio/python/ch-1.py
@@ -0,0 +1,18 @@
+#!/usr/bin/python3
+
+# Challenge 031
+#
+# Task #1
+# Create a function to check divide by zero error without checking if the
+# denominator is zero.
+
+def divide(num, den):
+ try:
+ res = num / den
+ except ZeroDivisionError:
+ return "division by zero trapped"
+ else:
+ return res
+
+print(divide(5, 2 ))
+print(divide(5, 0))
diff --git a/challenge-031/paulo-custodio/python/ch-2.py b/challenge-031/paulo-custodio/python/ch-2.py
new file mode 100644
index 0000000000..eb5675143d
--- /dev/null
+++ b/challenge-031/paulo-custodio/python/ch-2.py
@@ -0,0 +1,13 @@
+#!/usr/bin/python3
+
+# Challenge 031
+#
+# Task #2
+# Create a script to demonstrate creating dynamic variable name, assign a value
+# to the variable and finally print the variable. The variable name would be
+# passed as command line argument.
+
+import sys
+
+globals()[sys.argv[1]] = 10
+print(globals()[sys.argv[1]])