【问题标题】:Python - ValueError: sign must be an integer with the value 0 or 1Python - ValueError:符号必须是值为 0 或 1 的整数
【发布时间】:2018-10-25 22:19:01
【问题描述】:
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

【问题讨论】:

    标签: python valueerror


    【解决方案1】:

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

    Decimal(random.choice(random_percent_j))
    

    不是

    random.choice(Decimal(random_percent_j))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-28
      • 2020-04-01
      • 2018-02-22
      • 1970-01-01
      • 2019-05-07
      相关资源
      最近更新 更多