Python Forum
TypeError: 'float' object is not callable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: 'float' object is not callable
#1
The first time everything works, but when I try to run the code on the second round, it gives an error after entering the variable "average". What could be the problem? Thanks)

import math
import telebot
from telebot import types
 
token='***'
bot=telebot.TeleBot(token)
 
texts = list()
 
# после запуска бота получаем меню из двух кнопок
@bot.message_handler(commands=['start'])
def start(message):
    markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
    item1=types.KeyboardButton('Кнопка1')
    item2=types.KeyboardButton('Кнопка2')
    markup.add(item1, item2)
    bot.send_message(message.chat.id,'<b>Выберите одну из кнопок.</b>', parse_mode='html', reply_markup=markup)
 
# первый тип расчётов
@bot.message_handler(func = lambda message: message.text == 'Кнопка1')
def first(message):
    msg = bot.send_message(message.chat.id, '<b>Введите первое число.</b>', parse_mode='html')
    bot.register_next_step_handler(msg, second)
 
def second(message):
    global n
    n = int(message.text)
    msg = bot.send_message(message.chat.id, '<b>Введите второе число.</b>', parse_mode='html')
    bot.register_next_step_handler(msg, average)
 
def average(message):
    global average
    average = float(message.text)
 
    if average >= 5:
        bot.send_message(message.chat.id, f'<b>Введите коректные данные.</b>', parse_mode='html')
    x = 4.0
    while x < 5.01:
        if average >= x:
            pass
        else:
            averageNew = x - 0.049
 
            # минимальное значение
            average1 = average + 0.049
            n5 = (averageNew - average1) * n / (5 - averageNew)
            if math.ceil(n5) < 1:
                n5 = 1
            else:
                n5 = math.ceil(n5)
 
            # максимальное значение
            average2 = average - 0.049
            nN = (averageNew - average2) * n / (5 - averageNew)
            if math.ceil(nN) < 1:
                pass
            else:
                nN = math.ceil(nN)
 
            # запись расчётов в список
            if nN == n5:
                texts.append(f"{round(x, 2)} — {nN} шт.")
            else:
                texts.append(f"{round(x, 2)} — {n5}-{nN} шт.")
 
            x += 0.1
 
    bot.send_message(message.chat.id, f'<b>Список расчётов:</b>', parse_mode='html')
    bot.send_message(message.chat.id, "\n".join(texts), parse_mode='html')
 
# второй тип расчётов
@bot.message_handler(func = lambda message: message.text == 'Кнопка2')
def sorry(message):
    bot.send_message(message.chat.id, '<b>Данный тип калькулятора в разработке. Выберите другой вариант.</b>', parse_mode='html')
 
bot.polling(none_stop=True)
Reply


Messages In This Thread
TypeError: 'float' object is not callable - by TimofeyKolpakov - Dec-02-2022, 11:23 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I am getting this TypeError: 'TreasureMap' object is not subscriptable. makilakos 2 246 May-25-2024, 07:58 PM
Last Post: deanhystad
  python calculate float plus float is incorrect? sirocawa 6 555 Apr-16-2024, 01:45 PM
Last Post: DeaD_EyE
  TypeError: cannot pickle ‘_asyncio.Future’ object Abdul_Rafey 1 592 Mar-07-2024, 03:40 PM
Last Post: deanhystad
  error in class: TypeError: 'str' object is not callable akbarza 2 652 Dec-30-2023, 04:35 PM
Last Post: deanhystad
Bug TypeError: 'NoneType' object is not subscriptable TheLummen 4 894 Nov-27-2023, 11:34 AM
Last Post: TheLummen
  TypeError: 'NoneType' object is not callable akbarza 4 1,216 Aug-24-2023, 05:14 PM
Last Post: snippsat
  [NEW CODER] TypeError: Object is not callable iwantyoursec 5 1,598 Aug-23-2023, 06:21 PM
Last Post: deanhystad
  Need help with 'str' object is not callable error. Fare 4 961 Jul-23-2023, 02:25 PM
Last Post: Fare
  TypeError: 'float' object is not callable #1 isdito2001 1 1,173 Jan-21-2023, 12:43 AM
Last Post: Yoriz
  TypeError: a bytes-like object is required ZeroX 13 4,782 Jan-07-2023, 07:02 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020