无法让数据收集器显示值(继续显示 None 值)

Unable to get data collector to display values (Keeps displaying None value)

你好我目前正在使用 python telegram bot 创建我的 bot,目前我无法使用我的数据收集器(它也可以计算我的卡路里)来显示我想要的值)问题是它一直返回一个 None 值,有人知道解决方案为什么吗?

def cal_collector(user_input):
    cal = []
    if user_input.isnumeric() == True:
        cal.append(user_input)
    else:
        if str(user_input).lower == "math":
            if cal == False:
                return "0"
            total_calories = sum(cal)
            return str(total_calories)
   


def cal_calculator(update: Update,_: CallbackContext):
    query = update.callback_query
    query.answer()
    keyboard = [
        [InlineKeyboardButton("Back", callback_data = str(ONE))]
    ]
    reply_markup = InlineKeyboardMarkup(keyboard)
    
    query.edit_message_text(str(cal_collector("math")),reply_markup = reply_markup)
    return SECOND

def calorie_reply(update: Update,_ : CallbackContext):
    keyboard = [
        [InlineKeyboardButton("Back", callback_data = str(ONE))]
    ]
    reply_markup = InlineKeyboardMarkup(keyboard)
    user_input = update.message.text 
    cal_collector(user_input)
    update.message.reply_text(calorie_input(user_input),reply_markup = reply_markup)
    return SECOND

我知道我这样做的方法很垃圾 :') 所以如果有人有其他更好的解决方案来更好地将我的数据存储在 python 电报机器人中,我们将不胜感激! (我仍然不太确定如何为此使用 类 和对象)

没关系,事实证明问题是正如@BoarGules 所说的那样,这些值被丢弃了。此外,我以一种更简单的方式重组了代码。虽然它还没有用于用户输入的 isnumeric 过滤器,但我会尽我所能。这是任何感兴趣的人的附加代码。

    answer = "You have keyed in " + user_input + " calories! Click Back to go back to the main menu"
    
    return answer
    
#Storing Data in a class 

cal = []

# calculates total cals
def cal_calculator(update: Update,_: CallbackContext):
    query = update.callback_query
    query.answer()
    keyboard = [
        [InlineKeyboardButton("Back", callback_data = str(ONE))]
    ]
    reply_markup = InlineKeyboardMarkup(keyboard)
    
    
    
    query.edit_message_text(f'You have consumed {str(sum(cal))}',reply_markup = reply_markup)
    return SECOND



def calorie_reply(update: Update,_ : CallbackContext):
    keyboard = [
        [InlineKeyboardButton("Back", callback_data = str(ONE))]
    ]
    reply_markup = InlineKeyboardMarkup(keyboard)
    user_input = update.message.text 
    user_int = int(user_input)
    cal.append(user_int)
    update.message.reply_text(calorie_input(user_input),reply_markup = reply_markup)
    return SECOND