如何防止某人做某事超过一定百分比?

问题描述 投票:0回答:1

我知道问题的标题不是很清楚,但我不太知道该如何表达。所以,我的问题是,我是一个不和谐机器人的开发团队的一员,该机器人可以刺激股票市场。此功能的作用是允许一个人购买其他人的股票。我将如何做到这一点,以使一个人不能购买某人的某个百分比,比如说大约10%?

def create_buy_embed(percent, user_mention):
    if percent >= 1:
        displayed_percent = 100
    else:
        displayed_percent = round(percent * 100, 3)
    return discord.Embed(
        description=f"You've bought {displayed_percent}% of {user_mention}"
    )
python bots discord
1个回答
0
投票

仅根据您提供的信息,我假设百分比通常是0.0-1.0的值。假设是这种情况,这是一种方法:

def create_buy_embed(percent, user_mention):
    if percent >= 0.1:
        return discord.Embed(
            description=f"You can't buy that much!"
        )
    else:
        displayed_percent = round(percent * 100, 3)
    return discord.Embed(
        description=f"You've bought {displayed_percent}% of {user_mention}"
    )
© www.soinside.com 2019 - 2024. All rights reserved.