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

标签 python valueerror

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/

相关文章:

python - 找不到 pyinstaller 命令

python - ValueError:需要至少一个数组来连接

python-3.x - ValueError:Python3.X 中的 SpectralCoclustering 中的数组不得包含 infs 或 NaN

python - 使用 python 3 和 tkinter 中的 colorchooser 更改 tkinter 窗口中文本的颜色

python - ValueError:f(a) 和 f(b) 必须具有不同的符号

python - ValueError: Series.replace 不能使用 dict-value 和非 None to_replace

python - Openpyxl:使用 load_workbook 时为 'ValueError: Max value is 14'

python - GeoJSON 数据未显示在 Python folium map 中

python - Pandas - 选择列表中的无效条目

python - Django:如何替换/覆盖/更新/更改 FileField 的文件?