-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchallenge_01.py
More file actions
31 lines (25 loc) · 793 Bytes
/
challenge_01.py
File metadata and controls
31 lines (25 loc) · 793 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from string import join
import re
text = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj."
def next_char(char, step = 2):
""" counts next letter character
>>> next_char('a')
'c'
>>> next_char('z')
'b'
>>> next_char(')')
')'
"""
if re.match('[a-z]', char):
a = ord('a')
z = ord('z')
new_char = ord(char) + 2
if new_char > z:
return chr(new_char % z + a - 1)
else:
return chr(new_char)
return char
print join(map(next_char, text), '')
if __name__ == '__main__':
import doctest
doctest.testmod()