diff options
Diffstat (limited to 'challenge-212/sgreen/python')
| -rwxr-xr-x | challenge-212/sgreen/python/ch-1.py | 27 |
1 files changed, 27 insertions, 0 deletions
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:]) |
