Skip to content
Snippets Groups Projects
11.py 662 B
Newer Older
import json

in_file, js_file = input(), input()
res = {"count": 0, "positive_count": 0, "min": float("inf"),
       "max": float("-inf"), "sum": 0, "average": 0}

with open(in_file, "r", encoding="utf-8")as inp:
    for line in inp:
        for num in [int(i) for i in line.split()]:
            res["count"] += 1
            if num > 0:
                res["positive_count"] += 1
            res["min"] = min(res["min"], num)
            res["max"] = max(res["max"], num)
            res["sum"] += num

res["average"] = round((res["sum"] / res["count"]), 2)

with open(js_file, "w", encoding="UTF-8") as js:
    json.dump(res, js, ensure_ascii=False, indent=2)