繁体   English   中英

尝试在.format 中进行数学运算

[英]Trying to do math in .format

它做减法,但不做地板决定和加法

import discord
from discord.ext import commands

bot = discord.ext.commands.Bot(command_prefix = "$")


@bot.event

async def on_message(message):
  if 0 < int(message.content) < 153:
   await message.channel.send("you are in Bronze 1.  You are {} games away from Bronze 2".format(153 - int(message.content)//7 +1))
  if 153 < int(message.content) < 200:
   await message.channel.send("you are in Bronze 2")

由于您没有使用括号,因此153 - int(message.content)//7 +1)的顺序与153 - (int(message.content)//7) + 1作为乘法/除法的顺序相同在加法/减法之前。 从数学来看,我猜这不是你想要的。

还有一些旁注:

  • int(message)为 153 时,输入被完全忽略
  • 您应该对第二个块使用elif ,因为它不重叠。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM