aboutsummaryrefslogtreecommitdiff
path: root/challenge-275/zapwai/python
diff options
context:
space:
mode:
authorDavid Ferrone <zapwai@gmail.com>2024-06-25 14:52:59 -0400
committerDavid Ferrone <zapwai@gmail.com>2024-06-25 14:52:59 -0400
commit9176b5be1ef39da532650c77b4df098f2a2a448e (patch)
treeac8647fa9fa5ed4e3b6ba494b9f7bc1356909e28 /challenge-275/zapwai/python
parentb07b0b03e415426e49e0c43f71de0a27a3cc65a4 (diff)
downloadperlweeklychallenge-club-9176b5be1ef39da532650c77b4df098f2a2a448e.tar.gz
perlweeklychallenge-club-9176b5be1ef39da532650c77b4df098f2a2a448e.tar.bz2
perlweeklychallenge-club-9176b5be1ef39da532650c77b4df098f2a2a448e.zip
Week 275
Diffstat (limited to 'challenge-275/zapwai/python')
-rw-r--r--challenge-275/zapwai/python/ch-1.py25
-rw-r--r--challenge-275/zapwai/python/ch-2.py31
2 files changed, 56 insertions, 0 deletions
diff --git a/challenge-275/zapwai/python/ch-1.py b/challenge-275/zapwai/python/ch-1.py
new file mode 100644
index 0000000000..ed07e45940
--- /dev/null
+++ b/challenge-275/zapwai/python/ch-1.py
@@ -0,0 +1,25 @@
+def proc(sentence, keys) :
+ print("Input: Sentence =", sentence, "keys = ", keys)
+ num = 0
+ for word in sentence.split(" "):
+ tally = 0
+ for key in keys:
+ if key in word:
+ break
+ else:
+ tally += 1
+
+ if tally == len(keys):
+ num += 1
+
+ print("Output:", num)
+
+sentence = "Perl Weekly Challenge"
+keys = ['l', 'a']
+proc(sentence, keys)
+sentence = "Perl and Raku"
+keys = ['a']
+proc(sentence, keys)
+sentence = "Well done Team PWC"
+keys = ['l', 'o']
+proc(sentence, keys)
diff --git a/challenge-275/zapwai/python/ch-2.py b/challenge-275/zapwai/python/ch-2.py
new file mode 100644
index 0000000000..c593ac08fb
--- /dev/null
+++ b/challenge-275/zapwai/python/ch-2.py
@@ -0,0 +1,31 @@
+def shifty(c, d):
+ alph = 'abcdefghijklmnopqrstuvwxyz'
+ ind = alph.index(c)
+ A = list(alph)
+ return A[d + ind]
+
+def proc(stringy):
+ print("Input: str =", stringy);
+ lets = []
+ puts = []
+ for i in range(len(stringy)):
+ if i % 2 == 0:
+ let = stringy[i:i+1]
+ lets.append(let)
+ else:
+ put = shifty(lets[-1], ord(stringy[i:i+1]) - 48)
+ puts.append(put)
+ print("Output: ", end='')
+ for j in range((len(stringy)//2) ):
+ print(lets[j], puts[j], end='', sep='')
+ if (len(stringy)) % 2 == 1:
+ print(lets[-1], end='')
+ print("\n")
+
+stringy = 'a1c1e1'
+proc(stringy)
+stringy = 'a1b2c3d4'
+proc(stringy)
+stringy = 'b2b'
+proc(stringy)
+