diff --git "a/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 4/task_1.py" "b/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 4/task_1.py" new file mode 100644 index 0000000..9f2d083 --- /dev/null +++ "b/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 4/task_1.py" @@ -0,0 +1,12 @@ +# TODO решите задачу +import json + + +def task() -> float: + with open('input.json', 'r') as file: + data = json.load(file) + product_sum = sum(item["score"] * item["weight"] for item in data) + return round(product_sum, 3) + + +print(task()) diff --git "a/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 4/task_2.py" "b/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 4/task_2.py" new file mode 100644 index 0000000..2077471 --- /dev/null +++ "b/\320\233\320\260\320\261\320\276\321\200\320\260\321\202\320\276\321\200\320\275\320\260\321\217 \321\200\320\260\320\261\320\276\321\202\320\260 4/task_2.py" @@ -0,0 +1,25 @@ +# TODO импортировать необходимые молули +import json +import csv + +INPUT_FILENAME = "input.csv" +OUTPUT_FILENAME = "output.json" + + +def task(delimiter=',', line_terminator='\n') -> None: + with open(INPUT_FILENAME, newline='') as csvfile: + csvreader = csv.DictReader(csvfile, delimiter=delimiter) + data = [] + for row in csvreader: + data.append(row) + with open(OUTPUT_FILENAME, 'w') as jsonfile: + json.dump(data, jsonfile, indent=4) + + +if __name__ == '__main__': + # Нужно для проверки + task() + + with open(OUTPUT_FILENAME) as output_f: + for line in output_f: + print(line, end="")