
# Распаковка словаря с ключами и значениями
def func_1():
    d1 = {'key1': 1, 'key2': 2}
    d2 = {'key2': 1, 'key3': 2}
    d3 = {'a1': 1, **d2, **d1}
    print(d3)


def concatenate(**kwargs):
    ret = ""
    for x in kwargs.values():
        if (type(x) == list):
            ret += ''.join(str(x))
        else:
            ret += str(x)
    return ret


def create_actor(**kwargs):
    base_dict = {'name': 'Райан', 'surname': 'Рейнольдс', 'age': 47}
    for key, value in kwargs.items():
        base_dict[key] = value
    return base_dict


def info_kwargs(**kwargs):
    for key in sorted(kwargs):
        print(f'{key} = {kwargs[key]}')


def test_args(a, b, *args):
    print(a, b, args)


def print_scores(name, *args):
    print("Student name:", name)
    my_list = list(args)
    my_list.sort()
    for i in my_list:
        print(i)


def truncate_sentences(n, *args):
    print(n)
    for st in args:
        print(st[:n])


def make_strings_big(*args, reverse=False):
    for st in args:
        print(st.lower()) if reverse else print(st.upper())


def item_sum(*args, **kwargs):
    current_sum = 0
    for arg in args:
        current_sum += arg

    for kwarg in kwargs.values():
        current_sum += kwarg
    return current_sum


def calculate_high_low_avg(*args, log_to_console=False):
    average = (max(args) + min(args))/2
    if log_to_console:
        print(f'high={max(args)}, low={min(args)}, avg={average}')
    return average
    

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

tables = {
    1: {'name': 'Andrey', 'is_vip': True, 'order': {}},
    2: None,
    3: None,
    4: None,
    5: {'name': 'Vasiliy', 'is_vip': False, 'order': {}},
}


def is_table_free(table_number: int):
    return tables[table_number] is None


def get_free_tables():
    return [x[0] for x in tables.items() if x[1] is None]


def reserve_table(table_number: int, name: str, status=False):
    if is_table_free(table_number):
        tables[table_number] = {'name': name, 'is_vip': status, 'order': {}}


def delete_reservation(table_number):
    tables[table_number] = None


def make_order(table, **kwargs):
    menu = ["salad", "soup", "main_dish", "drink", "desert"]
    for key, value in kwargs.items():
        if key in menu:
            if key not in tables[table]['order'].keys():
                tables[table]['order'][key] = value.split(',')
            else:
                tables[table]['order'][key].extend(value.split(','))
            


def delete_order(*, number_table, delete_all=False, **kwargs):
    if delete_all:
        tables[number_table]['order'] = {}
    else:
        for key, value in kwargs.items():
            if value:
                tables[number_table]['order'].pop(key, None)

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


def main():
    # func_1()

    # print(concatenate(q='iHave', w="next", e="Coins", r=[10, 5, 10, 7]))
    # print(concatenate(q='iHave', w="next", e="Coins"))

    # print(create_actor())
    # print(create_actor(height=190, movies=['Дедпул', 'Главный герой']))

    # info_kwargs(c=43, b=32, a=32)
    # test_args(a=10, 1, 2, 3)

    # print_scores("Jud", 100, 95, 88, 92, 99)

    # my_list =[5, 19, 23, 88]
    # my_dict = {'a': 11, 'b': 23}

    # print(item_sum(*my_list, **my_dict))

    # calculate_high_low_avg(*my_list, log_to_console=True)

    make_order(1, soup='Borsh')
    make_order(1, soup='Лапша')
    
    make_order(1, soup='Borsh,Лапша', desert='Медовик', drink='Cola')

    for key, value in tables.items():
        print(key, value)

    '''    
    try:
        delete_order(number_table=1, delete_all=True)
    except TypeError:
        print('Вызов delete_order без передачи значения по ключу не должен проходить')
    else:
        raise ValueError('Проверьте типы параметров функции delete_order')
    '''
   
    # st = 'absd'
    # lst = st.split(',')
    # print(lst)



if __name__ == '__main__':
    main()