From 9176b5be1ef39da532650c77b4df098f2a2a448e Mon Sep 17 00:00:00 2001 From: David Ferrone Date: Tue, 25 Jun 2024 14:52:59 -0400 Subject: Week 275 --- challenge-275/zapwai/python/ch-1.py | 25 +++++++++++++++++++++++++ challenge-275/zapwai/python/ch-2.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 challenge-275/zapwai/python/ch-1.py create mode 100644 challenge-275/zapwai/python/ch-2.py (limited to 'challenge-275/zapwai/python') 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) + -- cgit