Python 数字只能在 y 到 x 之间

Python number can be only between y to x

有人可以帮我解决这个问题吗?

        if (bnb_spent) >= 0.00001 and (bnb_spent) <= 0.00004:
            # LOG.info(f'Nasrat, čislo je menší')
            pass
        else:    
            if (bnb_spent) >= 0.0003 and (bnb_spent) <= 0.0005:
                send_message1(message)
            else:
                if (bnb_spent) >= 0.08 and (bnb_spent) <= 0.1:
                    send_message2(message)
                else:
                    if (bnb_spent) >= 0.11 and (bnb_spent) <= 0.4:
                        send_message3(message)

TypeError: '>=' 在 'str' 和 'float'

的实例之间不受支持

如果数字不小于0.001但同时不大于0.003,我希望它发送消息

您的 bnb_spent 参数在执行该部分代码时是一个字符串。在比较之前尝试将其转换为浮点数。例如,您可以尝试(也稍微清理了 if-else):

        bnb_spent = float(bnb_spent)
        if (bnb_spent) >= 0.00001 and (bnb_spent) <= 0.00004:
            # LOG.info(f'Nasrat, čislo je menší')
            pass
        elif (bnb_spent) >= 0.0003 and (bnb_spent) <= 0.0005:
            send_message1(message)
        elif (bnb_spent) >= 0.08 and (bnb_spent) <= 0.1:
            send_message2(message)
        elif (bnb_spent) >= 0.11 and (bnb_spent) <= 0.4:
            send_message3(message)

可能变量bnb_spent是一个字符串。在给定的代码段之前添加行 bnb_spent = float(bnb_spent)