input: Write a function to encrypt a message using a given key in Python. The function should take two parameters: the message to be encrypted and the encryption key. It should return the encrypted message.
  assert encrypt("Hello world!", "secret")=="Tqxx{,uqy|+"
  assert encrypt("OpenAI", "key")=="TslrEl"
  assert encrypt("", "any")==""
  assert encrypt("Python", "code")=="[{\\[jtu"
  assert encrypt("Programming", "123")=="Qsptjohjbnf"
  
  
output: def encrypt(message, key):
      encrypted_message = ""
      key_length = len(key)
      for i, char in enumerate(message):
          shift = ord(key[i % key_length])
          if char.isalpha():
              base = ord('A') if char.isupper() else ord('a')
              encrypted_message += chr((ord(char) - base + shift) % 26 + base)
          else:
              encrypted_message += char
      return encrypted_message