Python 更改用户';将数字输入到百分比,并将该百分比添加到特定数字

Python 更改用户';将数字输入到百分比,并将该百分比添加到特定数字,python,discord.py,Python,Discord.py,简短版本:我希望能够在命令中提供一个数字作为参数,就像这样,!info food1 250然后,bot接受gatherSpeed变量并将用户提供的数字作为百分比相加。这样:316000(+250%=number 完整代码: @info.command(aliases=['Food1', 'f1', 'F1', 'tomato1', 'Tomato1']) async def food1(self, ctx, arg: int=0): currentDT = DT.dat

简短版本:我希望能够在命令中提供一个数字作为参数,就像这样,
!info food1 250
然后,bot接受
gatherSpeed
变量并将用户提供的数字作为百分比相加。这样:
316000(+250%=number

完整代码:

 @info.command(aliases=['Food1', 'f1', 'F1', 'tomato1', 'Tomato1'])
    async def food1(self, ctx, arg: int=0):
        currentDT = DT.datetime.now()
        gatherSpeed = (316000)
        resource = (64300)
        t1 = round((resource) / 108)
        t2 = round((resource) / 124)
        t3 = round((resource) / 142)
        t4 = round((resource) / 164)
        t5 = round((resource) / 188)
        t6 = round((resource) / 217)
        t7 = round((resource) / 249)
        t8 = round((resource) / 287)
        t9 = round((resource) / 330)
        t10 = round((resource) / 379)
        embedResource = discord.Embed(title='Food Tile, Level 1', 
                                    colour=discord.Colour(8596012), 
                                    description=f'Amount of food in tile: **{resource:,}**\nDefault gathering speed: **{gatherSpeed:,}/h**\n\nLevel I troops needed: **{t1:,}**\nLevel II troops needed: **{t2:,}**\nLevel III troops needed: **{t3:,}**\nLevel IV troops needed: **{t4:,}**\nLevel V troops needed: **{t5:,}**\nLevel VI troops needed: **{t6:,}**\n Level VII troops needed: **{t7:,}**\nLevel VIII troops needed: **{t8:,}**\nLevel IX troops needed: **{t9:,}**\nLevel X troops needed: **{t10:,}**', timestamp=currentDT)

        embedResource.set_thumbnail(url='https://cdn.discordapp.com/emojis/723743319389110312.png?v=1')
        embedResource.set_image(url='https://cdn.discordapp.com/attachments/713050313791242322/724817714467569695/image0.png')

        embedResourceArg = discord.Embed(title='Food Tile, Level 1', 
                                        colour=discord.Colour(8596012), 
                                        description=f'Amount of food in tile: **{resource:,}**\nYour gathering speed: **{gatherSpeed + arg + 100:,}/h**\n\nLevel I troops needed: **{t1:,}**\nLevel II troops needed: **{t2:,}**\nLevel III troops needed: **{t3:,}**\nLevel IV troops needed: **{t4:,}**\nLevel V troops needed: **{t5:,}**\nLevel VI troops needed: **{t6:,}**\n Level VII troops needed: **{t7:,}**\nLevel VIII troops needed: **{t8:,}**\nLevel IX troops needed: **{t9:,}**\nLevel X troops needed: **{t10:,}**', timestamp=currentDT)

        embedResourceArg.set_thumbnail(url='https://cdn.discordapp.com/emojis/723743319389110312.png?v=1')
        embedResourceArg.set_image(url='https://cdn.discordapp.com/attachments/713050313791242322/724817714467569695/image0.png')
        if arg != None:
            await ctx.send(embed=embedResourceArg)

        if not arg:
            return await ctx.send(embed=embedResource)
扩展版:我需要一些关于我的机器人的数学帮助。我正在为我玩的手机游戏编写一个小机器人。你可以训练军队、参战、收集资源等等。资源有不同的级别,级别1-8,每个级别都有固定的“收集速度”这可以通过研究或推动来增加,我称之为“聚集推动”

第18行是没有应用收集提升的嵌入,它发布默认收集速度。第25行是嵌入,它应该用收集提升+收集速度的总收集速度替换默认收集速度。在本例中,收集速度为316000。如果我愿意
!info food1 250
我想说收集速度是
1106000
。或者
316000+250%=1106000
。我该怎么做?
%
是我发现的模,从我能收集到的,我不能做类似
{gatherSpeed+arg%:,}


我知道现在是
{gatherSpeed+arg+100:,}
+100
只是我在测试。

我想你在寻找类似的东西:
gatherSpeed+gatherSpeed*2.5

若要添加一个百分比,您实际上只是将该百分比乘以100,因此n+0%=n*100%,n+50%=n*150%。若要乘以一个百分比,您需要先将该百分比除以100。因此n*150%=n*1.5

要在python中实现这一点,您需要编写
gatherSpeed*((arg/100.0)+1.0)
,因此将
{gatherSpeed+arg+100:,}
替换为
{gatherSpeed*((arg/100.0)+1.0:,}


此外,您不需要将未修改的版本放在第18行,因为如果
arg
=
0
,则这将导致
gatherSpeed*1.0
=
gatherSpeed

这将是
gatherSpeed*(1+arg/100)
Thank you@BEN1JEN。这很有效!同时也感谢您在第18行提供的提示,现在看起来好多了:D