Python - ValueError: знак должен быть целым числом со значением 0 или 1 - PullRequest
0 голосов
/ 16 мая 2018
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

1 Ответ

0 голосов
/ 16 мая 2018

Вы создаете экземпляр объекта Decimal со списком (random_percent_j) в последней строке кода.Должно быть:

Decimal(random.choice(random_percent_j))

не

random.choice(Decimal(random_percent_j))
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...