import string
import random


def password(length: int = 16):
    """
    Creates a secure password of the specified length.
    """
    foobar = []
    chars = list(string.ascii_letters + string.digits + "!@#$%^&*()")
    random.shuffle(chars)

    try:
        if length > 16:
            raise ValueError(
                "The password can be no longer than 16 characters and no shorter than eight characters."
            )
        elif length < 8:
            raise ValueError(
                "The password can be no longer than 16 characters and no shorter than eight characters."
            )
        else:
            for i in range(length):
                foobar.append(random.choice(chars))
            return "".join(foobar)
    except Exception as e:
        raise e