aboutsummaryrefslogtreecommitdiff
path: root/challenge-072/paulo-custodio/python/ch-2.py
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-09-20 21:40:27 +0100
committerGitHub <noreply@github.com>2024-09-20 21:40:27 +0100
commitb521af146ef7c2bd338bc5355e2fc8f6c49cbd30 (patch)
tree8d8e24fcdbb56212b91343e1306cce425826dc53 /challenge-072/paulo-custodio/python/ch-2.py
parent962fb60ab30715e2dedc4fda8619042d22fba65e (diff)
parent4ae5477a9bc6c8b01ee984ed6a5a90dbec170833 (diff)
downloadperlweeklychallenge-club-b521af146ef7c2bd338bc5355e2fc8f6c49cbd30.tar.gz
perlweeklychallenge-club-b521af146ef7c2bd338bc5355e2fc8f6c49cbd30.tar.bz2
perlweeklychallenge-club-b521af146ef7c2bd338bc5355e2fc8f6c49cbd30.zip
Merge pull request #10874 from pauloscustodio/master
Add Python solution to challenge 067
Diffstat (limited to 'challenge-072/paulo-custodio/python/ch-2.py')
-rw-r--r--challenge-072/paulo-custodio/python/ch-2.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/challenge-072/paulo-custodio/python/ch-2.py b/challenge-072/paulo-custodio/python/ch-2.py
new file mode 100644
index 0000000000..6d897d5b2b
--- /dev/null
+++ b/challenge-072/paulo-custodio/python/ch-2.py
@@ -0,0 +1,40 @@
+#!/usr/bin/env perl
+
+# Challenge 072
+#
+# TASK #2 > Lines Range
+# Submitted by: Mohammad S Anwar
+# You are given a text file name $file and range $A - $B where $A <= $B.
+#
+# Write a script to display lines range $A and $B in the given file.
+#
+# Example
+# Input:
+# $ cat input.txt
+# L1
+# L2
+# L3
+# L4
+# ...
+# ...
+# ...
+# ...
+# L100
+# $A = 4 and $B = 12
+# Output:
+# L4
+# L5
+# L6
+# L7
+# L8
+# L9
+# L10
+# L11
+# L12
+
+import sys
+FILE, A, B = sys.argv[1], int(sys.argv[2]), int(sys.argv[3])
+
+f = open(sys.argv[1], "r")
+lines = [x.rstrip("\n") for x in f.readlines()]
+print("\n".join(lines[A-1:B]))