首页 > 解决方案 > 尝试以 .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")

标签: pythondiscord.py

解决方案


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

还有一些旁注:

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

推荐阅读