【问题标题】:Can anyone help me with my currency shop? [closed]任何人都可以帮我处理我的货币商店吗? [关闭]
【发布时间】:2019-08-07 01:16:49
【问题描述】:

我对 python 有点陌生,但我知道变量和字符串等基础知识,我最近创建了一个包含货币和商店的不和谐机器人。这家商店不工作,它的意思是让我为列出的物品买一张票(它不是为了存储任何东西)。请你帮我找出我哪里出错并帮助我改善或给我看我哪里出错了哪里可以找到我的答案。这是我为商店买的(注意我使用的是 python 3.6.4):

@client.command(pass_context = True)
async def buy(ctx, item):
    items = {
    "Apex Legends":[3,20],
    "Minecraft":[5,30],
    "Halo":[5,20],
    "Fortnite":[8,10],
    }
while True:
    print("Apex Legends = 3BP / Minecraft = 5BP / Halo = 5BP / Fortnite = 8BP")
    print("Account Balance bp",stash)
    choice = input("What would you like to buy?: ").strip().title()
    if choice in items:
        if items[choice][1]>0:
            if stash>=items[choice][0]:
                items[choice][1]=items[choice][1]-1
                stash= stash-items[choice][0]
                print("Thank you..!")
                print("")
            else:
                print("Sorry you don\'t enough money...")
                print("")
        else:
            print("sorry sold out")
            print("")
    else:
        print("Sorry we don\'t have that item...")
        print("")

如果您想在机器人上查看我的完整代码,请点击此处: https://hastebin.com/tojadefajo.py

【问题讨论】:

  • 您的代码的具体错误或意外响应是什么?
  • 当我启动机器人时,我的其他命令都不起作用,当我查看控制台时,它显示了我能做什么,但是在不和谐时,我希望它显示在不和谐而不是控制台上

标签: python python-3.x bots


【解决方案1】:
  1. 您不需要while True:,因为您没有break 语句,这将进入无限循环!
  2. await client.say() 语句替换所有print() 语句

试试这个

@client.command(pass_context = True)
async def buy(ctx, item):
    items = {
        "Apex Legends": [3, 20],
        "Minecraft": [5, 30],
        "Halo": [5, 20],
        "Fortnite": [8, 10],
    }
    await client.say("Apex Legends = 3BP / Minecraft = 5BP / Halo = 5BP / Fortnite = 8BP")
    await client.say("Account Balance bp", stash)
    choice = input("What would you like to buy?: ").strip().title()
    if choice in items:
        if items[choice][1]>0:
            if stash>=items[choice][0]:
                items[choice][1]=items[choice][1]-1
                stash= stash-items[choice][0]
                await client.say("Thank you..!")
                await client.say("")
            else:
                await client.say("Sorry you dont enough money...")
                await client.say("")
        else:
            await client.say("sorry sold out")
            await client.say("")
    else:
        await client.say("Sorry we don't have that item...")
        await client.say("")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-14
    • 1970-01-01
    • 2013-10-09
    • 2021-01-14
    • 1970-01-01
    • 2021-01-04
    • 1970-01-01
    • 2014-01-25
    相关资源
    最近更新 更多