Files

23 lines
847 B
Python

def encrypt(s):
"""Create a function encrypt that takes a string as an argument and
returns a string encrypted with the alphabet being rotated.
The alphabet should be rotated in a manner such that the letters
shift down by two multiplied to two places.
For example:
encrypt('hi') returns 'lm'
encrypt('asdfghjkl') returns 'ewhjklnop'
encrypt('gf') returns 'kj'
encrypt('et') returns 'ix'
"""
result = ""
for char in s:
if char.isalpha():
shift = 2 * 2 # two multiplied to two = 4
if char.islower():
new_char = chr((ord(char) - ord('a') + shift) % 26 + ord('a'))
else:
new_char = chr((ord(char) - ord('A') + shift) % 26 + ord('A'))
result += new_char
else:
result += char
return result