How to optimize this code?

There is code: (called c imported file config.py)
def catalog(message):
 if message.text == c.games_list[0]:
 bot.send_photo(message.chat.id, c.games_photo[0], c.games_list[0] + "\price:: "+ str(c.games_price[0]) + "RUB")
 elif message.text == c.games_list[1]:
 bot.send_photo(message.chat.id, c.games_photo[1], c.games_list[1] + "\price:: "+ str(c.games_price[1]) + "RUB")
 elif message.text == c.games_list[2]:
 bot.send_photo(message.chat.id, c.games_photo[2], p.games_list[2] + "\price:: "+ str(c.games_price[2]) + "RUB")
 elif message.text == c.games_list[3]:
 bot.send_photo(message.chat.id, c.games_photo[3], p.games_list[3] + "\price:: "+ str(c.games_price[3]) + "RUB")
 elif message.text == c.games_list[4]:
 bot.send_photo(message.chat.id, c.games_photo[4], p.games_list[4] + "\price:: "+ str(c.games_price[4]) + "RUB")
 elif message.text == c.games_list[5]:
 bot.send_photo(message.chat.id, c.games_photo[5], p.games_list[5] + "\price:: "+ str(c.games_price[5]) + "RUB")
 elif message.text == c.games_list[6]:
 bot.send_photo(message.chat.id, c.games_photo[6], p.games_list[6] + "\price:: "+ str(c.games_price[6]) + "RUB")
 elif message.text == c.games_list[7]:
 bot.send_photo(message.chat.id, c.games_photo[7], p.games_list[7] + "\price:: "+ str(c.games_price[7]) + "RUB")


Code file config.py:
games_list = ["GTA V (Rockstar Key)", "Raft (Steam Gift)", "Rust (Steam Account)", "Rust (Steam Gift)", "Tom Clancy's Rainbow Six Siege (Uplay key)", "PUBG (Steam key)", "Minecraft Win 10 (Key)", "Minecraft Java (Account)"]

games_price = [651, 391, 524, 767, 486, 634, 159, 159]

games_photo = ["https://i.imgur.com/Qq32qtA.jpg", "https://i.imgur.com/S4YmRwv.jpg", "https://i.imgur.com/YKThcpO.jpg", "https://i.imgur.com/YKThcpO.jpg", "https://i.imgur.com/wewkvqe.jpg", "https://i.imgur.com/SnwO0vo.jpg", "https://i.imgur.com/7q0Qdkh.png", "https://i.imgur.com/7q0Qdkh.png"]

If anything, using a library telebot (https://github.com/eternnoir/pyTelegramBotAPI)
April 7th 20 at 10:51
2 answers
April 7th 20 at 10:53
Solution
Cycle.
I don't quite understand how to do it under the loop. Can write the final code please. - hardy72 commented on April 7th 20 at 10:56
Why?
i = c.games_list.index(message.text) if message.text in c.games_list.index else -1
- layla commented on April 7th 20 at 10:59
@layla, How does that translate into code? - hardy72 commented on April 7th 20 at 11:02
@hardy72, you already pushed in two directions. Try to understand. If someone is willing to write the solutions themselves you will not write to learn. - Adelbert59 commented on April 7th 20 at 11:05
April 7th 20 at 10:55
Solution
def catalog(message):
try:
 index_of_text = c.games_list.index(message.text)
 except ValueError:
 print('the message.text is missing from games_list !!!')
 bot.send_photo(message.chat.id, c.games_photo[index_of_text], p.games_list[index_of_text] +
 "\price:: "+ str(c.games_price[index_of_text]) + "RUB")
Just started hearing, thank you - hardy72 commented on April 7th 20 at 10:58

Find more questions by tags Python