input: Write a function to generate a random password with a length of 8 characters, ensuring it contains at least one uppercase letter, one lowercase letter, one digit, and one special character. The function should not take any input and should return the generated password as a string.
  
  def generate_password():
     up_alphabet = string.ascii_uppercase
     low_alphabet = string.ascii_lowercase
     digits = string.digits
     symbols = string.punctuation
     length = 8
     pass_characters = up_alphabet + low_alphabet + digits + symbols
     password =  ''.join(random.sample(pass_characters, length))
     return password
  
  assert len(generate_password()) == 8
  assert any(c.isupper() for c in generate_password()) == True
  assert any(c.islower() for c in generate_password()) == True
  assert any(c.isdigit() for c in generate_password()) == True
  assert any(c in string.punctuation for c in generate_password()) == True
output: import random
  import string
  
  def generate_password():
      up_alphabet = string.ascii_uppercase
      low_alphabet = string.ascii_lowercase
      digits = string.digits
      symbols = string.punctuation
      length = 8
      while True:
          password = ''.join(random.choice(up_alphabet + low_alphabet + digits + symbols) for _ in range(length))
          if (any(c.isupper() for c in password) and
              any(c.islower() for c in password) and
              any(c.isdigit() for c in password) and
              any(c in symbols for c in password)):
              return password