import random


def generate_password(length):
    """Generate a password of a desired length with numbers, symbols, upper
    and lowercase letters"""
    if length < 4:
        raise ValueError('length must be 4 or greater')

    lower_chars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
                   'm', 'n', 'o', 'p',
                   'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
    upper_chars = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
                   'M', 'N', 'O',
                   'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
    symbols = ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+', '_']
    digits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
    count = 0
    password = ""
    choices = ['lower', 'upper', 'symbols', 'digits']
    while count < length:
        if len(choices) == 0:
            choices = ['lower', 'upper', 'symbols', 'digits']

        current_char = random.choice(choices)

        if current_char == 'lower':
            password += random.choice(lower_chars)
            choices.remove('lower')
        elif current_char == 'upper':
            password += random.choice(upper_chars)
            choices.remove('upper')
        elif current_char == 'symbols':
            password += random.choice(symbols)
            choices.remove('symbols')
        elif current_char == 'digits':
            password += random.choice(digits)
            choices.remove('digits')
        count += 1

    return password