aboutsummaryrefslogtreecommitdiff
path: root/challenge-275/packy-anderson/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-275/packy-anderson/python/ch-2.py')
-rwxr-xr-xchallenge-275/packy-anderson/python/ch-2.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/challenge-275/packy-anderson/python/ch-2.py b/challenge-275/packy-anderson/python/ch-2.py
new file mode 100755
index 0000000000..0b5a0d57ce
--- /dev/null
+++ b/challenge-275/packy-anderson/python/ch-2.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+
+def replaceDigits(str):
+ last_letter = str[0:1]
+ out = ''
+ for c in str:
+ if c.isnumeric():
+ out += chr( ord(last_letter) + int(c) )
+ else:
+ out += c
+ last_letter = c
+ return out
+
+def solution(str):
+ print(f"Input: $str = '{str}'")
+ print(f"Output: '{replaceDigits(str)}'")
+
+print('Example 1:')
+solution("a1c1e1")
+
+print('\nExample 2:')
+solution("a1b2c3d4")
+
+print('\nExample 3:')
+solution("b2b")
+
+print('\nExample 4:')
+solution("a16z")