From 2fdb31d3b27d4d1809484091e5b36cfefdff5c6c Mon Sep 17 00:00:00 2001 From: Paulo Custodio Date: Thu, 23 Dec 2021 12:21:58 +0000 Subject: Add Perl and Python solutions to challenge 031 --- challenge-031/paulo-custodio/python/ch-1.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 challenge-031/paulo-custodio/python/ch-1.py (limited to 'challenge-031/paulo-custodio/python/ch-1.py') 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)) -- cgit