input: Write a python function to encrypt a string using a Caesar cipher with a given key.
  assert encrypt("hello", 3) == "khoor"
  assert encrypt("abcxyz", 2) == "cdezab"
  assert encrypt("python", 5) == "udymts"
output: def encrypt(text, key):
      encrypted_text = ""
      for char in text:
          if char.isalpha():
              shift = ord('a') if char.islower() else ord('A')
              encrypted_text += chr((ord(char) - shift + key) % 26 + shift)
          else:
              encrypted_text += char
      return encrypted_text