aboutsummaryrefslogtreecommitdiff
path: root/challenge-273/luca-ferrari/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-273/luca-ferrari/python')
-rw-r--r--challenge-273/luca-ferrari/python/ch-1.py23
-rw-r--r--challenge-273/luca-ferrari/python/ch-2.py26
2 files changed, 49 insertions, 0 deletions
diff --git a/challenge-273/luca-ferrari/python/ch-1.py b/challenge-273/luca-ferrari/python/ch-1.py
new file mode 100644
index 0000000000..00e24b5173
--- /dev/null
+++ b/challenge-273/luca-ferrari/python/ch-1.py
@@ -0,0 +1,23 @@
+#!python
+
+#
+# Perl Weekly Challenge 273
+# Task 1
+#
+# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-273>
+#
+
+import sys
+
+# task implementation
+# the return value will be printed
+def task_1( args ):
+ s = args[ 0 ]
+ c = args[ 1 ]
+
+ return round( len( list( filter( lambda x: x == c, s ) ) ) / len( s ) * 100 )
+
+
+# invoke the main without the command itself
+if __name__ == '__main__':
+ print( task_1( sys.argv[ 1: ] ) )
diff --git a/challenge-273/luca-ferrari/python/ch-2.py b/challenge-273/luca-ferrari/python/ch-2.py
new file mode 100644
index 0000000000..98cb99df7a
--- /dev/null
+++ b/challenge-273/luca-ferrari/python/ch-2.py
@@ -0,0 +1,26 @@
+#!python
+
+#
+# Perl Weekly Challenge 273
+# Task 2
+#
+# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-273>
+#
+
+import sys
+import re
+
+# task implementation
+# the return value will be printed
+def task_2( args ):
+ s = args[ 0 ]
+ p1 = re.compile( 'b' )
+ p2 = re.compile( 'b.*a' )
+ return p1.search( s ) and not p2.search( s )
+
+
+
+
+# invoke the main without the command itself
+if __name__ == '__main__':
+ print( task_2( sys.argv[ 1: ] ) )