-
Notifications
You must be signed in to change notification settings - Fork 0
/
challenge1.py
33 lines (21 loc) · 926 Bytes
/
challenge1.py
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
32
33
# http://www.pythonchallenge.com/pc/def/map.html
original_string = "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."
new_string = ""
# try
for i in range(len(original_string)):
old_char = original_string[i]
if ord(old_char) >= ord("a") and ord(old_char) <= ord ("z"):
new_char = chr(ord("a") + (ord(old_char)+2 - ord("a")) % (ord("z")-ord("a")+1))
else:
new_char = old_char
new_string += new_char
print new_string
# solution
import string
stringin = "abcdefghijklmnopqrstuvwxyz"
stringout = "cdefghijklmnopqrstuvwxyzab"
translation = string.maketrans(stringin, stringout)
new_string = original_string.translate(translation)
print new_string
# next
print "http://www.pythonchallenge.com/pc/def/map.html".translate(translation)