Python 尝试用.format做数学
它执行减法运算,但不执行楼层决策和加法运算Python 尝试用.format做数学,python,discord.py,Python,Discord.py,它执行减法运算,但不执行楼层决策和加法运算 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.sen
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")
导入不一致
从discord.ext导入命令
bot=discord.ext.commands.bot(命令前缀=“$”)
@机器人事件
异步def on_消息(消息):
如果0
由于没有使用括号,153-int(message.content)//7+1)
的顺序与153-(int(message.content)//7)+1的顺序相同,因为乘法/除法在加法/减法之前。从数学上看,我猜那不是你想要的
还有一些旁注:
- 如果
int(message)
为153,则完全忽略输入
- 第二个块应该使用
elif
,因为它不重叠
作为提示:您可以使用range()
函数来提高代码的可读性。类似这样:如果int(message.content)在范围(1153)内:
当您得到意外输出时,是什么消息
?另外,请包含此数学表达式的意图153-int(message.content)//7+1
。如果没有人知道结果应该是什么,那么很难说出正确的值。您还应该在问题中包括当前输出和所需输出!我真的不明白