gpt4 book ai didi

Python-值错误: sign must be an integer with the value 0 or 1

转载 作者:行者123 更新时间:2023-11-30 22:15:09 24 4
gpt4 key购买 nike

with open("{}.json".format(ctx.message.author.id), "r") as json_file:
profileData = json.load(json_file)
data = profileData[ctx.message.author.id]

with open("attacks.json") as json_data:
items = json.load(json_data)

thing = "soldier"
data[thing + "#"] = "{}".format(int(data[thing + "#"]) - int(soldier))
thing = "sniper"
data[thing + "#"] = "{}".format(int(data[thing + "#"]) - int(sniper))
thing = "demolitionist"
data[thing + "#"] = "{}".format(int(data[thing + "#"]) - int(demolit))
thing = "spy"
data[thing + "#"] = "{}".format(int(data[thing + "#"]) - int(spy))
thing = "armored_vehicle"
data[thing + "#"] = "{}".format(int(data[thing + "#"]) - int(armored_vehicle))
thing = "tank"
data[thing + "#"] = "{}".format(int(data[thing + "#"]) - int(tank))

random_percent_j = ["1.1", "1.25", "1.4"]
data["balance"] = "{}".format(int(data["balance"]) + int(items["1"]["deploy_cost"]) * int(soldier) * random.choice(Decimal(random_percent_j)))

这就是我得到的结果,我以前从未见过这种类型的错误。其中一些是 JSON,因此代码如下:https://hastebin.com/hoseyikove.json

  File "run.py", line 220, in attack
data["balance"] = "{}".format(int(data["balance"]) + int(items["1"]["deploy_cost"]) * int(soldier) * random.choice(Decimal(random_percent_j)))
ValueError: sign must be an integer with the value 0 or 1

最佳答案

您将在最后一行代码中使用列表 (random_percent_j) 实例化一个 Decimal 对象。应该是:

Decimal(random.choice(random_percent_j))

不是

random.choice(Decimal(random_percent_j))

关于Python-值错误: sign must be an integer with the value 0 or 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50361085/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com