I'm having trouble with this function. def encrypt(msg, code): '''(str, str) -> str Return msg encrypted using the given code. The code is an ordering of the alphabet plus the space and '.' characters. The position of each character in the code string gives the index of the replacement character in the regular alphabet 'abcdefghijklmnopqrstuvwxyz .'
In the first example below, 'h' is in position 20, so we
select the letter in position 20 in the alphabet, or 'u'.
>>> encrypt('hello there', '. zyxwvutsrqponmlkjihgfedcba')
'uxqqnbiuxkx'
>>> encrypt('hello there', '. zaybxcwdveuftgshriqjpkolnm')
'rlzzyborlsl'
'''
alpha = 'abcdefghijklmnopqrstuvwxyz'
i = 0
for char in len(msg[i]):
if msg[i] == code and msg[i] == alpha[i]:
return msg
I have that, but it doesn't work. Can anybody help me out please?