python - 尝试以 .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
出现在加法/减法之前。从数学来看,我猜这不是你想要的。
还有一些旁注:
- 当 if
int(message)
为 153 时,输入被完全忽略 - 您应该使用
elif
第二个块,因为它不重叠。
推荐阅读
- python - LightGBM 错误:ValueError:对于提前停止,评估需要至少一个数据集和评估指标
- java - 从字符串数组生成所有可能的组合而不重复
- c++ - 我可以在类中有一个命名的 lambda 函数作为变量并尝试从主函数调用命名的 lambda 吗?
- windows - 在 Windows Docker 容器 (NSIS) 内静默安装
- python - 删除 json 文件中所有出现的键
- firebase - 无法进行 Firebase 身份验证登录
- python - 详细页面的网页设计
- instagram - 使用 Facebook 应用程序帐户或任何其他方式发送/阅读 Instagram 直接消息
- c# - 如何将内容从一个用户控件移动到另一个,windows窗体,c#
- android - 无法检索用户位置