input: Write a function to generate a random password of length 8 characters, ensuring it contains at least one lowercase letter, one uppercase letter, one digit, and one special character. If the length is not provided, the default value should be 8.
  def generate_password(length=8):
      import string
      import random
      # special characters
      special_characters = "!#$%&'()*+,-./:;<=>?@[\]^_`{|}~"
      # generating password
      password = random.choice(string.ascii_lowercase) + random.choice(string.ascii_uppercase) + random.choice(string.digits) + random.choice(special_characters)
      for i in range(length - 4):
          password += random.choice(string.ascii_lowercase + string.ascii_uppercase + string.digits + special_characters)
      password = ''.join(random.sample(password, len(password)))
      return password
  
  assert len(generate_password())==8
  assert any(c.islower() for c in generate_password())==True
  assert any(c.isupper() for c in generate_password())==True
  assert any(c.isdigit() for c in generate_password())==True
  assert any(c in "!#$%&'()*+,-./:;<=>?@[\]^_`{|}~" for c in generate_password())==True
  assert len(generate_password(10))==10
output: def generate_password(length=8):
      import string
      import random
      special_characters = "!#$%&'()*+,-./:;<=>?@[\]^_`{|}~"
      password = random.choice(string.ascii_lowercase) + random.choice(string.ascii_uppercase) + random.choice(string.digits) + random.choice(special_characters)
      for i in range(length - 4):
          password += random.choice(string.ascii_lowercase + string.ascii_uppercase + string.digits + special_characters)
      password = ''.join(random.sample(password, len(password)))
      return password