Implement a function crypto() where every character at a odd position i in the alphabet will be encrypted with the character at position i+1 and every character at an even position i will be encrypted with the character at position i-1. Or like, ‘a’ is encrypted with ‘b’, ‘b’ with ‘a’, ‘c’ with ‘d’, ‘d’ with ‘c’, ‘e’ with ‘f’, ‘f’ with ‘e’, etc.
This should appear:
>>>>crypto('abc')
bad
>>>>crypto('OOZ')
PPY
***ATTEMPT
def crypto():
return [ord(c) in s]
s = 'cat'
alist = ascii_list(s)
print alist
alist[0] +=1
alist[1] +=14
I’m almost positive I’m coming at this all wrong.
Here is what you want:
EXPLANATION:
cin the strings(that’sfor c in spart)ord('a')andord('A')are both odd (very useful!), so …(1 if ord(c)%2 else -1)part evaluates to1for oddord(c)and-1for even onesord(c)and usechrto obtain the “encrypted” character''.join()