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/input.csv" "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/input.csv" new file mode 100644 index 0000000..0e76d03 --- /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/input.csv" @@ -0,0 +1,5 @@ +longitude,latitude,housing_median_age,total_rooms,total_bedrooms,population,households,median_income,median_house_value +-122.050000,37.370000,27.000000,3885.000000,661.000000,1537.000000,606.000000,6.608500,344700.000000 +-118.300000,34.260000,43.000000,1510.000000,310.000000,809.000000,277.000000,3.599000,176500.000000 +-117.810000,33.780000,27.000000,3589.000000,507.000000,1484.000000,495.000000,5.793400,270500.000000 +-118.360000,33.820000,28.000000,67.000000,15.000000,49.000000,11.000000,6.135900,330000.000000 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/input.json" "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/input.json" new file mode 100644 index 0000000..33a9637 --- /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/input.json" @@ -0,0 +1,34 @@ +[ + { + "score": 0.0009456152645028281, + "weight": 1 + }, + { + "score": 0.00020640167757499364, + "weight": 1 + }, + { + "score": 0, + "weight": 1 + }, + { + "score": 1.6557065217391307, + "weight": 1 + }, + { + "score": 0, + "weight": 1 + }, + { + "score": 0.6066065217391303, + "weight": 1 + }, + { + "score": 0.03126181644071977, + "weight": 1 + }, + { + "score": 0.001253973281817707, + "weight": 1 + } +] \ No newline at end of file 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/output.json" "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/output.json" new file mode 100644 index 0000000..15094eb --- /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/output.json" @@ -0,0 +1,46 @@ +[ + { + "longitude": "-122.050000", + "latitude": "37.370000", + "housing_median_age": "27.000000", + "total_rooms": "3885.000000", + "total_bedrooms": "661.000000", + "population": "1537.000000", + "households": "606.000000", + "median_income": "6.608500", + "median_house_value": "344700.000000" + }, + { + "longitude": "-118.300000", + "latitude": "34.260000", + "housing_median_age": "43.000000", + "total_rooms": "1510.000000", + "total_bedrooms": "310.000000", + "population": "809.000000", + "households": "277.000000", + "median_income": "3.599000", + "median_house_value": "176500.000000" + }, + { + "longitude": "-117.810000", + "latitude": "33.780000", + "housing_median_age": "27.000000", + "total_rooms": "3589.000000", + "total_bedrooms": "507.000000", + "population": "1484.000000", + "households": "495.000000", + "median_income": "5.793400", + "median_house_value": "270500.000000" + }, + { + "longitude": "-118.360000", + "latitude": "33.820000", + "housing_median_age": "28.000000", + "total_rooms": "67.000000", + "total_bedrooms": "15.000000", + "population": "49.000000", + "households": "11.000000", + "median_income": "6.135900", + "median_house_value": "330000.000000" + } +] \ No newline at end of file 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..8202cce --- /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,13 @@ +import json + + +def task(path) -> float: + with open(path, 'r') as f: + data = json.load(f) + + sum_of_products = sum([element["score"] * element["weight"] for element in data]) + + return round(sum_of_products, 3) + + +print(task("input.json")) 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..a9bf416 --- /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,26 @@ +import csv +import json + + +INPUT_FILENAME = "input.csv" +OUTPUT_FILENAME = "output.json" + + +def task() -> None: + data = [] + with open(INPUT_FILENAME, 'r') as f: + reader = csv.DictReader(f) + for row in reader: + data.append(row) + + with open(OUTPUT_FILENAME, 'w') as f: + json.dump(data, f, indent=4) + + +if __name__ == '__main__': + # Нужно для проверки + task() + + with open(OUTPUT_FILENAME) as output_f: + for line in output_f: + print(line, end="")