Python Challenge second question string replacement

Push the letters in the string back by two, for example, a becomes c, z becomes b, and other characters remain unchanged.

 1 def convert_string(aString):
 2         bString = ' '
 3         for i in aString:
 4             if ord('a')<=ord(i)<=ord('w') or ord('A')<=ord(i)<=ord('W'):
 5                 k = chr(ord(i)+2)
 6             elif i == 'y' or i == 'z':
 7                 k = chr (ord ( ' a ' ) + 1 + ord (i) -ord ( ' z ' ))
 8              elif i == ' Y '  or i == ' Z ' :
 9                  k = chr (ord ( ' A ' ) + 1 + ord (i) -ord ( ' Z ' ))
 10              else :
 11                  k = i
 12              bString + = k
 13          return bString

Effect:

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326043926&siteId=291194637