pythonchallenge.com第二题

这道题不难,但是开始理解错题了,搞了半天都没出来

#!/usr/bin/env python
str = '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 maketranslate(str):

	strs = '' 

	for i in range(len(str)):

	    if str[i] == 'y':

		strs = strs + 'a'

		continue

	    elif str[i] == 'z':

		strs = strs + 'b'

		continue

	    elif str[i] == '.':

		strs = strs + '.'

		continue

	    elif str[i] == '(':

		strs = strs + '('

		continue

	    elif str[i] == ')':

		strs = strs + ')'

		continue

	    if str[i] != ' ': 

		strs = strs + chr(ord(str[i])+ord('m')-ord('k'))

	    else:

		strs = strs + ' '

	return strs


print maketranslate(str)

print maketranslate('map')


代码还是写的很挫

你可能感兴趣的:(第二题)