python - 任何人都可以帮我处理我的货币商店吗?
问题描述
我对 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
解决方案
- 您不需要,
while True:
因为这将进入无限循环,因为您没有break
语句! - 用语句替换所有
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("")
推荐阅读
- python - 安装 Jupyter 扩展 - 从 setup.py 自动安装和启用
- sql - SSIS 开发人员表达式
- c++ - 使用 bazel 构建的二进制文件在 pprof 中查看源代码
- c++ - 声明具有可变维度的二维数组
- c++ - 如果你有两个全局函数,一个用于 `Widget`,另一个用于 `double`,而 `Widget` 类定义了 cast-to-double,会发生什么?
- c# - 使用 C# 和实体框架技术构建数据库
- c++ - C++ 使用向量实现合并排序
- html - 下拉自动建议从选择中隐藏列表项
- javascript - 使用 JavaScript 中的另一个时间范围从一个时间范围计算重叠时间
- terraform - terraform 云远程后端的 terraform 导入失败