From 6d9f9d89ba086af0198b7d335c046e4096d38fde Mon Sep 17 00:00:00 2001 From: Simon Green Date: Mon, 10 Apr 2023 20:17:58 +1000 Subject: Simon's solution to task 1, challenge 212 --- challenge-212/sgreen/python/ch-1.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 challenge-212/sgreen/python/ch-1.py (limited to 'challenge-212/sgreen/python') diff --git a/challenge-212/sgreen/python/ch-1.py b/challenge-212/sgreen/python/ch-1.py new file mode 100755 index 0000000000..aac0116d02 --- /dev/null +++ b/challenge-212/sgreen/python/ch-1.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 + +import sys +import string + + +def main(array): + original_word = array.pop(0) + lower_alphabet = list(string.ascii_lowercase) + upper_alphabet = list(string.ascii_uppercase) + new_word = '' + + for i, original_letter in enumerate(original_word): + # Which alphabet? + alphabet = lower_alphabet if original_letter in lower_alphabet else upper_alphabet + + # Calculate position of new letter + pos = (alphabet.index(original_letter) + int(array[i])) % 26 + + # ... and add it to the string + new_word += alphabet[pos] + + print(new_word) + + +if __name__ == '__main__': + main(sys.argv[1:]) -- cgit