Проблема в словаре dict_inventory. Питон. pyTelegramBotAPI

Делаю бота. И 1 из некоторых функций является Инвентарь. Тобишь добавление в пустой словарь ключ и само значение. Но максимум этих значений можно только 10. Значение force - количество предметов в инвентаре. Сама ошибка - IndexError: list index out of range. Ошибки выдает по-разному. Может выдать когда предметов 1, а может и когда 6 например. На мой "крутой" украинский не обращайте внимания.


Вот код.

force = 0

elif call.data == 'back':
bot.send_message(call.message.chat.id, 'Вертаємося в меню...')
force = force + 1
dict_inventory[price_details_autos] = products_auto
forcee(call.message)

def forcee(message):
global force
if force == 11:
    bot.send_message(message.chat.id, 'Максімум 10 предмеів в інвентарі.')
    dict_inventory.pop(price_details_autos, None)
    force = 10
    menu(message)
    return
elif force != 11:
    menu(message)
    return

def inventory(message):
if force == 1 and len(dict_inventory) > 0:
    bot.send_message(message.chat.id, '1| ' + str(list(dict_inventory.values())[0]), reply_markup = markup)
    bot.register_next_step_handler(message, inventory_continue)
elif force == 2 and len(dict_inventory) > 1:
    bot.send_message(message.chat.id, '1| ' + str(list(dict_inventory.values())[0]) + '\n2| ' + str(list(dict_inventory.values())[1]), reply_markup = markup)
    bot.register_next_step_handler(message, inventory_continue)
elif force == 3 and len(dict_inventory) > 2:
    bot.send_message(message.chat.id, '1| ' + str(list(dict_inventory.values())[0]) + '\n2| ' + str(list(dict_inventory.values())[1]) + '\n3| ' + str(list(dict_inventory.values())[2]), reply_markup = markup)
    bot.register_next_step_handler(message, inventory_continue)
elif force == 4 and len(dict_inventory) > 3:
    bot.send_message(message.chat.id, '1| ' + str(list(dict_inventory.values())[0]) + '\n2| ' + str(list(dict_inventory.values())[1]) + '\n3| ' + str(list(dict_inventory.values())[2]) + '\n4| ' + str(list(dict_inventory.values())[3]), reply_markup = markup)
    bot.register_next_step_handler(message, inventory_continue)
elif force == 5 and len(dict_inventory) > 4:
    bot.send_message(message.chat.id, '1| ' + str(list(dict_inventory.values())[0]) + '\n2| ' + str(list(dict_inventory.values())[1]) + '\n3| ' + str(list(dict_inventory.values())[2]) + '\n4| ' + str(list(dict_inventory.values())[3]) + '\n5| ' + str(list(dict_inventory.values())[4]), reply_markup = markup)
    bot.register_next_step_handler(message, inventory_continue)
elif force == 6 and len(dict_inventory) > 5:
    bot.send_message(message.chat.id, '1| ' + str(list(dict_inventory.values())[0]) + '\n2| ' + str(list(dict_inventory.values())[1]) + '\n3| ' + str(list(dict_inventory.values())[2]) + '\n4| ' + str(list(dict_inventory.values())[3]) + '\n5| ' + str(list(dict_inventory.values())[4]) + '\n6| ' + str(list(dict_inventory.values())[5]), reply_markup = markup)
    bot.register_next_step_handler(message, inventory_continue)
elif force == 7 and len(dict_inventory) > 6:
    bot.send_message(message.chat.id, '1| ' + str(list(dict_inventory.values())[0]) + '\n2| ' + str(list(dict_inventory.values())[1]) + '\n3| ' + str(list(dict_inventory.values())[2]) + '\n4| ' + str(list(dict_inventory.values())[3]) + '\n5| ' + str(list(dict_inventory.values())[4]) + '\n6| ' + str(list(dict_inventory.values())[5])  + '\n7| ' + str(list(dict_inventory.values())[6]), reply_markup = markup)
    bot.register_next_step_handler(message, inventory_continue)
elif force == 8 and len(dict_inventory) > 7:
    bot.send_message(message.chat.id, '1| ' + str(list(dict_inventory.values())[0]) + '\n2| ' + str(list(dict_inventory.values())[1]) + '\n3| ' + str(list(dict_inventory.values())[2]) + '\n4| ' + str(list(dict_inventory.values())[3]) + '\n5| ' + str(list(dict_inventory.values())[4]) + '\n6| ' + str(list(dict_inventory.values())[5])  + '\n7| ' + str(list(dict_inventory.values())[6]) + '\n8| ' + str(list(dict_inventory.values())[7]), reply_markup = markup)
    bot.register_next_step_handler(message, inventory_continue)
elif force == 9 and len(dict_inventory) > 8:
    bot.send_message(message.chat.id, '1| ' + str(list(dict_inventory.values())[0]) + '\n2| ' + str(list(dict_inventory.values())[1]) + '\n3| ' + str(list(dict_inventory.values())[2]) + '\n4| ' + str(list(dict_inventory.values())[3]) + '\n5| ' + str(list(dict_inventory.values())[4]) + '\n6| ' + str(list(dict_inventory.values())[5])  + '\n7| ' + str(list(dict_inventory.values())[6]) + '\n8| ' + str(list(dict_inventory.values())[7]) + '\n9| ' + str(list(dict_inventory.values())[8]), reply_markup = markup)
    bot.register_next_step_handler(message, inventory_continue)
elif force == 10 and len(dict_inventory) > 9:
    bot.send_message(message.chat.id, '1| ' + str(list(dict_inventory.values())[0]) + '\n2| ' + str(list(dict_inventory.values())[1]) + '\n3| ' + str(list(dict_inventory.values())[2]) + '\n4| ' + str(list(dict_inventory.values())[3]) + '\n5| ' + str(list(dict_inventory.values())[4]) + '\n6| ' + str(list(dict_inventory.values())[5])  + '\n7| ' + str(list(dict_inventory.values())[6]) + '\n8| ' + str(list(dict_inventory.values())[7]) + '\n9| ' + str(list(dict_inventory.values())[8]) + '\n10| ' + str(list(dict_inventory.values())[9]), reply_markup = markup)
    bot.register_next_step_handler(message, inventory_continue)
elif not dict_inventory:
    bot.send_message(message.chat.id, 'Стопе, твій інвентар пустий... Вертаю в меню. ')
    menu(message)
    return

Ответы (0 шт):