首页 > 解决方案 > 任何人都可以帮我处理我的货币商店吗?

问题描述

我对 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

标签: pythonpython-3.xbots

解决方案


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

尝试这个

@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("")

推荐阅读