import telebot
from currency_converter import CurrencyConverter
from telebot import types, callback_data
bot = telebot.TeleBot('Token')
currency = CurrencyConverter()
amount = 0
@bot.message_handler(commands=['start'])
def welcome(message):
bot.send_message(message.chat.id, "Привет!\nЯ БОТ Конвертер валют\nОтправьте мне cумму, которую хотите просмотреть")
bot.register_next_step_handler(message, cash)
def cash(message):
global amount
try:
amount = int(message.text.strip())
except ValueError:
bot.send_message(message.chat.id, 'Error! Please, write correct number.')
bot.register_next_step_handler(message, cash)
return
if amount > 0:
mark = types.InlineKeyboardMarkup(row_width=2)
b1 = types.InlineKeyboardButton('USD/EUR', callback_data='usdeur')
b2 = types.InlineKeyboardButton('EUR/PLN', callback_data='eurpln')
b3 = types.InlineKeyboardButton('USD/PLN', callback_data='usdpln')
b4 = types.InlineKeyboardButton('BYN/PLN', callback_data='bynpln')
b5 = types.InlineKeyboardButton('Other value', callback_data='else')
mark.add(b1, b2, b3, b4, b5)
bot.send_message(message.chat.id, 'Please, change', reply_markup=mark)
else:
bot.send_message(message.chat.id, 'Error! Please, write correct number.')
bot.register_next_step_handler(message, cash)
@bot.callback_query_handler(func=lambda call: True)
def callback(call):
value = call.data.upper().split('/')
result = currency.convert(amount, value[0], value[1])
bot.send_message(call.message.chat.id, f'Result: {result}. You can repeat')
bot.register_next_step_handler(call.message, cash)
bot.polling(none_stop=True)
Oшибка:
result = currency.convert(amount, value[0], value[1])
~~~~~^^^
IndexError: list index out of range