aboutsummaryrefslogtreecommitdiff
path: root/challenge-322/packy-anderson/python/ch-1.py
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-05-25 10:03:02 +0100
committerGitHub <noreply@github.com>2025-05-25 10:03:02 +0100
commit0ab31bd5fe6c07040d84ac6bc877d16aa762bf06 (patch)
treeea16b147691228812f3664d36a9f973d2569c1b0 /challenge-322/packy-anderson/python/ch-1.py
parent7c768b927743ab5f69dfe30e283fb371b466b511 (diff)
parent0af5f73f09593ee4c911f1eb8ff0733019ddb826 (diff)
downloadperlweeklychallenge-club-0ab31bd5fe6c07040d84ac6bc877d16aa762bf06.tar.gz
perlweeklychallenge-club-0ab31bd5fe6c07040d84ac6bc877d16aa762bf06.tar.bz2
perlweeklychallenge-club-0ab31bd5fe6c07040d84ac6bc877d16aa762bf06.zip
Merge pull request #12071 from packy/master
Challenge 322 solutions by Packy Anderson
Diffstat (limited to 'challenge-322/packy-anderson/python/ch-1.py')
-rwxr-xr-xchallenge-322/packy-anderson/python/ch-1.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/challenge-322/packy-anderson/python/ch-1.py b/challenge-322/packy-anderson/python/ch-1.py
new file mode 100755
index 0000000000..a42c02c26a
--- /dev/null
+++ b/challenge-322/packy-anderson/python/ch-1.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+
+def strFormat(strVar, i):
+ strVar = strVar.replace("-", "")
+ output = ''
+ while (len(strVar) > i):
+ output = "-" + strVar[-i:] + output
+ strVar = strVar[0:-i] # Python strings are IMMUTABLE
+ return strVar + output
+
+def solution(strVar, i):
+ print(f'Input: $str = "{strVar}", $i = {i}')
+ output = strFormat(strVar, i)
+ print(f'Output: "{output}"')
+
+
+print('Example 1:')
+solution("ABC-D-E-F", 3)
+
+print('\nExample 2:')
+solution("A-BC-D-E", 2)
+
+print('\nExample 3:')
+solution("-A-B-CD-E", 4)
+
+print('\nExample 4:')
+solution("-A-B-CD-E", 5) \ No newline at end of file