aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-031/paulo-custodio/Makefile2
-rw-r--r--challenge-031/paulo-custodio/README1
-rw-r--r--challenge-031/paulo-custodio/perl/ch-1.pl19
-rw-r--r--challenge-031/paulo-custodio/perl/ch-2.pl16
-rw-r--r--challenge-031/paulo-custodio/python/ch-1.py18
-rw-r--r--challenge-031/paulo-custodio/python/ch-2.py13
-rw-r--r--challenge-031/paulo-custodio/t/test-1.yaml7
-rw-r--r--challenge-031/paulo-custodio/t/test-2.yaml5
8 files changed, 81 insertions, 0 deletions
diff --git a/challenge-031/paulo-custodio/Makefile b/challenge-031/paulo-custodio/Makefile
new file mode 100644
index 0000000000..c3c762d746
--- /dev/null
+++ b/challenge-031/paulo-custodio/Makefile
@@ -0,0 +1,2 @@
+all:
+ perl ../../challenge-001/paulo-custodio/test.pl
diff --git a/challenge-031/paulo-custodio/README b/challenge-031/paulo-custodio/README
new file mode 100644
index 0000000000..87dc0b2fbd
--- /dev/null
+++ b/challenge-031/paulo-custodio/README
@@ -0,0 +1 @@
+Solution by Paulo Custodio
diff --git a/challenge-031/paulo-custodio/perl/ch-1.pl b/challenge-031/paulo-custodio/perl/ch-1.pl
new file mode 100644
index 0000000000..7e96de6302
--- /dev/null
+++ b/challenge-031/paulo-custodio/perl/ch-1.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/perl
+
+# Challenge 031
+#
+# Task #1
+# Create a function to check divide by zero error without checking if the
+# denominator is zero.
+
+use Modern::Perl;
+
+sub divide {
+ my($num, $den) = @_;
+ my $res = eval { $num / $den };
+ return "division by zero trapped" if $@;
+ return $res;
+}
+
+say divide(5, 2);
+say divide(5, 0);
diff --git a/challenge-031/paulo-custodio/perl/ch-2.pl b/challenge-031/paulo-custodio/perl/ch-2.pl
new file mode 100644
index 0000000000..0647281291
--- /dev/null
+++ b/challenge-031/paulo-custodio/perl/ch-2.pl
@@ -0,0 +1,16 @@
+#!/usr/bin/perl
+
+# 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.
+
+use Modern::Perl;
+no strict 'refs';
+
+my $name = shift || die "Usage: ch-2.pl name\n";
+
+${$name} = 10;
+say ${$name};
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]])
diff --git a/challenge-031/paulo-custodio/t/test-1.yaml b/challenge-031/paulo-custodio/t/test-1.yaml
new file mode 100644
index 0000000000..7451f174a9
--- /dev/null
+++ b/challenge-031/paulo-custodio/t/test-1.yaml
@@ -0,0 +1,7 @@
+- setup:
+ cleanup:
+ args:
+ input:
+ output: |
+ 2.5
+ division by zero trapped
diff --git a/challenge-031/paulo-custodio/t/test-2.yaml b/challenge-031/paulo-custodio/t/test-2.yaml
new file mode 100644
index 0000000000..7a099edf5c
--- /dev/null
+++ b/challenge-031/paulo-custodio/t/test-2.yaml
@@ -0,0 +1,5 @@
+- setup:
+ cleanup:
+ args: name
+ input:
+ output: 10