From 0b028ef0d53dcc6ff0ae528f2ee141dff5f06a71 Mon Sep 17 00:00:00 2001 From: Kharitonov Vitaly Date: Sat, 1 Feb 2020 11:52:29 +0300 Subject: [PATCH 1/3] HW3 --- phw3.ipynb | 272 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 272 insertions(+) create mode 100644 phw3.ipynb diff --git a/phw3.ipynb b/phw3.ipynb new file mode 100644 index 0000000..6c69a87 --- /dev/null +++ b/phw3.ipynb @@ -0,0 +1,272 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Задание #1. Введите: 1\n", + "Задание #2. Введите: 2\n", + "Задание #3. Введите: 3\n", + "Задание #4. Введите: 4 или 42\n", + "Задание #5. Введите: 5\n", + "Задание #6. Введите: 6\n", + "\n", + "Выберите задание или введите \"0\", чтобы выйти: 6\n", + "Input text: 3\n", + "3\n", + "Задание #1. Введите: 1\n", + "Задание #2. Введите: 2\n", + "Задание #3. Введите: 3\n", + "Задание #4. Введите: 4 или 42\n", + "Задание #5. Введите: 5\n", + "Задание #6. Введите: 6\n", + "\n", + "Выберите задание или введите \"0\", чтобы выйти: 1\n", + "Enter first number: 6\n", + "Enter second number: 3\n", + "2.0\n", + "\n", + "\n", + "Задание #1. Введите: 1\n", + "Задание #2. Введите: 2\n", + "Задание #3. Введите: 3\n", + "Задание #4. Введите: 4 или 42\n", + "Задание #5. Введите: 5\n", + "Задание #6. Введите: 6\n", + "\n", + "Выберите задание или введите \"0\", чтобы выйти: 2\n", + "Enter name: kolya\n", + "Enter second name: kare\n", + "Enter birth day: 34\n", + "Enter live town: la\n", + "Enter email: kkk@mail.com\n", + "Enter tel number: 67763\n", + "['kolya', 'kare', '34', 'la', 'kkk@mail.com', '67763']\n", + "\n", + "\n", + "Задание #1. Введите: 1\n", + "Задание #2. Введите: 2\n", + "Задание #3. Введите: 3\n", + "Задание #4. Введите: 4 или 42\n", + "Задание #5. Введите: 5\n", + "Задание #6. Введите: 6\n", + "\n", + "Выберите задание или введите \"0\", чтобы выйти: 3\n", + "Enter first number: 4\n", + "Enter second number: 2\n", + "Enter third number: 5\n", + "9\n", + "\n", + "\n", + "Задание #1. Введите: 1\n", + "Задание #2. Введите: 2\n", + "Задание #3. Введите: 3\n", + "Задание #4. Введите: 4 или 42\n", + "Задание #5. Введите: 5\n", + "Задание #6. Введите: 6\n", + "\n", + "Выберите задание или введите \"0\", чтобы выйти: 4\n", + "Enter first number: 4\n", + "Enter second number: 2\n", + "0.0625\n", + "\n", + "\n", + "Задание #1. Введите: 1\n", + "Задание #2. Введите: 2\n", + "Задание #3. Введите: 3\n", + "Задание #4. Введите: 4 или 42\n", + "Задание #5. Введите: 5\n", + "Задание #6. Введите: 6\n", + "\n", + "Выберите задание или введите \"0\", чтобы выйти: 9\n", + "Задание #1. Введите: 1\n", + "Задание #2. Введите: 2\n", + "Задание #3. Введите: 3\n", + "Задание #4. Введите: 4 или 42\n", + "Задание #5. Введите: 5\n", + "Задание #6. Введите: 6\n", + "\n", + "Выберите задание или введите \"0\", чтобы выйти: 42\n", + "Enter first number: 9\n", + "Enter second number: 3\n", + "0.00015241579027587258\n", + "\n", + "\n", + "Задание #1. Введите: 1\n", + "Задание #2. Введите: 2\n", + "Задание #3. Введите: 3\n", + "Задание #4. Введите: 4 или 42\n", + "Задание #5. Введите: 5\n", + "Задание #6. Введите: 6\n", + "\n", + "Выберите задание или введите \"0\", чтобы выйти: 5\n", + "Enter list of number or * to exit: 234 3242\n", + "Sum is 3476 + \"\n", + "\"\n", + "Enter list of number or * to exit: fg3\n", + "Enter number or *\n", + "Sum is 3476 + \"\n", + "\"\n", + "Enter list of number or * to exit: *\n", + "Sum is 3476. Exit + \"\n", + "\"\n", + "Задание #1. Введите: 1\n", + "Задание #2. Введите: 2\n", + "Задание #3. Введите: 3\n", + "Задание #4. Введите: 4 или 42\n", + "Задание #5. Введите: 5\n", + "Задание #6. Введите: 6\n", + "\n", + "Выберите задание или введите \"0\", чтобы выйти: 6\n", + "Input text: hello world\n", + "Hello World\n", + "Задание #1. Введите: 1\n", + "Задание #2. Введите: 2\n", + "Задание #3. Введите: 3\n", + "Задание #4. Введите: 4 или 42\n", + "Задание #5. Введите: 5\n", + "Задание #6. Введите: 6\n", + "\n", + "Выберите задание или введите \"0\", чтобы выйти: 0\n" + ] + } + ], + "source": [ + "def Division(a, b):\n", + " try:\n", + " return a / b\n", + " except ZeroDivisionError:\n", + " return 'Zero Division Error'\n", + " except ValueError:\n", + " return \"Wrong input. It's must be numbers\"\n", + " \n", + "def Division_use():\n", + " print(Division((int(input('Enter first number: '))), (int(input('Enter second number: ')))))\n", + " print('\\n')\n", + " \n", + "def Data(**kwargs):\n", + " return list(kwargs.values())\n", + " \n", + "def Data_use():\n", + " print(Data(name = input('Enter name: '),\n", + " s_name = input('Enter second name: '),\n", + " b_date = input('Enter birth day: '),\n", + " l_town = input('Enter live town: '),\n", + " email = input('Enter email: '),\n", + " tel = input('Enter tel number: ')))\n", + " print('\\n')\n", + " \n", + "def My_func(a, b, c):\n", + " s = [a, b, c]\n", + " s.remove(min(a, b, c))\n", + " return sum(s)\n", + " \n", + " \n", + "def My_func_use():\n", + " print(My_func((int(input('Enter first number: '))), (int(input('Enter second number: '))), (int(input('Enter third number: ')))))\n", + " print('\\n')\n", + " \n", + "def My_func_2(x, y):\n", + " return 1 / x ** abs(y)\n", + "\n", + "def My_func_2_use():\n", + " print(My_func_2((int(input('Enter first number: '))), (int(input('Enter second number: ')))))\n", + " print('\\n')\n", + " \n", + "def My_func_2_1(x, y):\n", + " for i in range(abs(y - 1)):\n", + " x *= x\n", + " return 1 / x\n", + "\n", + "def My_func_2_1_use():\n", + " print(My_func_2_1((int(input('Enter first number: '))), (int(input('Enter second number: ')))))\n", + " print('\\n')\n", + "\n", + "def E_5():\n", + " res = 0\n", + " while True:\n", + " numbers = input('Enter list of number or * to exit: ').split()\n", + " for i in numbers:\n", + " try:\n", + " if i == '*':\n", + " print(f'Sum is {res}. Exit + \"\\n\"')\n", + " return\n", + " else:\n", + " res += int(i)\n", + " except ValueError:\n", + " print('Enter number or *')\n", + " print(f'Sum is {res} + \"\\n\"')\n", + "\n", + "def Int_func(text):\n", + " ls = []\n", + " for i in range(len(text)):\n", + " ls.append(text[i][0:1].title() + text[i][1:])\n", + " return ' '.join(ls)\n", + " print('\\n')\n", + "\n", + "def Int_func_use():\n", + " print(Int_func(input('Input text: ').split()))\n", + " \n", + "def functions():\n", + " print('Задание #1. Введите: 1')\n", + " print('Задание #2. Введите: 2')\n", + " print('Задание #3. Введите: 3')\n", + " print('Задание #4. Введите: 4 или 42')\n", + " print('Задание #5. Введите: 5')\n", + " print('Задание #6. Введите: 6' + '\\n')\n", + " \n", + "menu = {1: Division_use,\n", + " 2: Data_use,\n", + " 3: My_func_use,\n", + " 4: My_func_2_use,\n", + " 42: My_func_2_1_use,\n", + " 5: E_5,\n", + " 6: Int_func_use}\n", + " \n", + "action = 1\n", + " \n", + "while action != 0:\n", + " functions()\n", + " action = int(input('Выберите задание или введите \"0\", чтобы выйти: '))\n", + " if action == 0:\n", + " break\n", + " if action in menu:\n", + " x = menu[action]\n", + " x()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From ac2d0391e065289d839ff921ff22bc583f56586f Mon Sep 17 00:00:00 2001 From: Kharitonov Vitaly Date: Mon, 3 Feb 2020 22:26:28 +0300 Subject: [PATCH 2/3] HW4 --- phw4.ipynb | 201 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 phw4.ipynb diff --git a/phw4.ipynb b/phw4.ipynb new file mode 100644 index 0000000..0f8e2ad --- /dev/null +++ b/phw4.ipynb @@ -0,0 +1,201 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Введите кол-во отработанных часов: 10\n", + "Введите часовую ставку: 1000\n", + "Введите размер премии: 2500\n", + "з/п составила: 12500\n" + ] + } + ], + "source": [ + "def salary():\n", + " x = int(input('Введите кол-во отработанных часов: '))\n", + " y = int(input('Введите часовую ставку: '))\n", + " c = int(input('Введите размер премии: '))\n", + " pay = x * y\n", + " return pay + c\n", + "print(f'з/п составила: {salary() }')" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[6, 18, 16, 12, 24, 99]\n" + ] + } + ], + "source": [ + "list_1 = [4, -3, 6, -4, -11, 18, 13, 16, 9, 12, -3, 24, 99, 21]\n", + "list_2 = [list_1[i] for i in range(1, len(list_1)) if int(list_1[i]) > int(list_1[i - 1])]\n", + "\n", + "print(list_2)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[20, 21, 40, 42, 60, 63, 80, 84, 100, 105, 120, 126, 140, 147, 160, 168, 180, 189, 200, 210, 220, 231, 240]\n" + ] + } + ], + "source": [ + "print(f'{[i for i in range(20, 241) if not i % 20 or not i % 21]}')" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[4, 13, 16]\n" + ] + } + ], + "source": [ + "list_1 = [4, 2, 6, 2, 6, 6, 13, 16]\n", + "list_2 = [i for i in list_1 if list_1.count(i) < 2]\n", + "print(list_2)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Список четных чисел [100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 188, 190, 192, 194, 196, 198, 200, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 222, 224, 226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 248, 250, 252, 254, 256, 258, 260, 262, 264, 266, 268, 270, 272, 274, 276, 278, 280, 282, 284, 286, 288, 290, 292, 294, 296, 298, 300, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 322, 324, 326, 328, 330, 332, 334, 336, 338, 340, 342, 344, 346, 348, 350, 352, 354, 356, 358, 360, 362, 364, 366, 368, 370, 372, 374, 376, 378, 380, 382, 384, 386, 388, 390, 392, 394, 396, 398, 400, 402, 404, 406, 408, 410, 412, 414, 416, 418, 420, 422, 424, 426, 428, 430, 432, 434, 436, 438, 440, 442, 444, 446, 448, 450, 452, 454, 456, 458, 460, 462, 464, 466, 468, 470, 472, 474, 476, 478, 480, 482, 484, 486, 488, 490, 492, 494, 496, 498, 500, 502, 504, 506, 508, 510, 512, 514, 516, 518, 520, 522, 524, 526, 528, 530, 532, 534, 536, 538, 540, 542, 544, 546, 548, 550, 552, 554, 556, 558, 560, 562, 564, 566, 568, 570, 572, 574, 576, 578, 580, 582, 584, 586, 588, 590, 592, 594, 596, 598, 600, 602, 604, 606, 608, 610, 612, 614, 616, 618, 620, 622, 624, 626, 628, 630, 632, 634, 636, 638, 640, 642, 644, 646, 648, 650, 652, 654, 656, 658, 660, 662, 664, 666, 668, 670, 672, 674, 676, 678, 680, 682, 684, 686, 688, 690, 692, 694, 696, 698, 700, 702, 704, 706, 708, 710, 712, 714, 716, 718, 720, 722, 724, 726, 728, 730, 732, 734, 736, 738, 740, 742, 744, 746, 748, 750, 752, 754, 756, 758, 760, 762, 764, 766, 768, 770, 772, 774, 776, 778, 780, 782, 784, 786, 788, 790, 792, 794, 796, 798, 800, 802, 804, 806, 808, 810, 812, 814, 816, 818, 820, 822, 824, 826, 828, 830, 832, 834, 836, 838, 840, 842, 844, 846, 848, 850, 852, 854, 856, 858, 860, 862, 864, 866, 868, 870, 872, 874, 876, 878, 880, 882, 884, 886, 888, 890, 892, 894, 896, 898, 900, 902, 904, 906, 908, 910, 912, 914, 916, 918, 920, 922, 924, 926, 928, 930, 932, 934, 936, 938, 940, 942, 944, 946, 948, 950, 952, 954, 956, 958, 960, 962, 964, 966, 968, 970, 972, 974, 976, 978, 980, 982, 984, 986, 988, 990, 992, 994, 996, 998, 1000]\n", + "Результат перемножения всех элементов списка 11663575674444359823002008139390746528142707402328361705647495301216245827892256323421573853031635648105175857107321864360366071385039128549679496343675509640183219826717346573458260381851930244150425562315833417515264123698581740276921937117732298873364203269398167251131992557619396626253824845619285980851485012131859200089180731617159967796785692496658820266554970195579987101761437467345295469560091019643416890744175485355715583034412689664621367823158491721734017238669568797130683826947437814864890599291484009747561514288528353178159298856645624289518581586947168677504742711452824976368290519747367284033226821443792754573564848344600041433089899538479032717299413920051538113896509134682791976736868238046387230383008696853107977931851651379555533347652931008271572588724198961970056163028633888796670948358527288343719100865852117339478785474064397937004993302565523495403857150309972891503340949896943795594807214141508464167055846685872109706922589562538698747726222566785521882450614299594376824656706451033378744188256788426310583732611392640652066952551824890922829689995132928000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n" + ] + } + ], + "source": [ + "from functools import reduce\n", + "\n", + "def my_func(i1, i2):\n", + " return i1 * i2\n", + "\n", + "print(f'Список четных чисел {[i for i in range(99, 1001) if i % 2 == 0]}')\n", + "print(f'Результат перемножения всех элементов {reduce(my_func, [i for i in range(99, 1001) if i % 2 == 0])}')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from itertools import count\n", + "\n", + "for i in count(int(input('Введите число '))):\n", + " print(i) \n", + "\n", + "from itertools import cycle\n", + "\n", + "list_1 = [True, 'ABC', 123, None]\n", + "for i in cycle(list_1):\n", + " print(i) " + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "2\n", + "6\n", + "24\n", + "120\n", + "720\n", + "5040\n", + "40320\n", + "362880\n", + "3628800\n", + "39916800\n", + "479001600\n", + "6227020800\n", + "87178291200\n", + "1307674368000\n" + ] + } + ], + "source": [ + "from itertools import count\n", + "from math import factorial\n", + "\n", + "def fibo_gen():\n", + " for i in count(1):\n", + " yield factorial(i)\n", + "\n", + "gen = fibo_gen()\n", + "x = 0\n", + "for i in gen:\n", + " if x < 15:\n", + " print(i)\n", + " x += 1\n", + " else:\n", + " break " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From 3fad2d3cf1b3dc6f925e1679f2266d8299fd2b43 Mon Sep 17 00:00:00 2001 From: Kharitonov Vitaly Date: Sat, 8 Feb 2020 10:55:31 +0300 Subject: [PATCH 3/3] HW5 --- phw5.ipynb | 259 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 259 insertions(+) create mode 100644 phw5.ipynb diff --git a/phw5.ipynb b/phw5.ipynb new file mode 100644 index 0000000..68f4721 --- /dev/null +++ b/phw5.ipynb @@ -0,0 +1,259 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello\n", + "World\n", + "\n" + ] + } + ], + "source": [ + "#1\n", + "\n", + "f = open('file1.txt','w+')\n", + "while True:\n", + " s = input()\n", + " if s == '': break\n", + " f.write(s + '\\n')\n", + "f.close()" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5 letters in line Hello\n", + "\n", + "5 letters in line World\n", + "\n", + "String count is 2\n" + ] + } + ], + "source": [ + "#2\n", + "\n", + "with open(\"file1.txt\") as f:\n", + " lines = 0\n", + " letters = 0\n", + " for line in f:\n", + " lines += line.count(\"\\n\")\n", + " letters = len(line)-1\n", + " print(f\"{letters} letters in line {line}\")\n", + " print(f\"String count is {lines}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "#3\n", + "\n", + "workers = {'Cеливанов': 18, 'Петрова': 25, 'Иванов': 30, 'Гришина': 45}\n", + "f = open(\"file2.txt\", 'w+')\n", + "for last_name, salary in workers.items():\n", + " f.write(last_name + ':' + str(salary) + \"\\n\")\n", + "f.close()" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Cеливанов:18\n", + "Петрова:25\n", + "Иванов:30\n", + "Гришина:45\n", + "workers: ['Cеливанов']\n", + "averate: 29.5\n" + ] + } + ], + "source": [ + "summa = 0\n", + "count = 0\n", + "workers = []\n", + "with open(\"file2.txt\", \"r\") as f:\n", + " for line in f:\n", + " print(line, end=\"\")\n", + " tokens = line.split(':')\n", + " if int(tokens[1]) < 20:\n", + " workers.append(tokens[0])\n", + " summa += int(tokens[1])\n", + " count += 1\n", + "result = summa / count\n", + "print(f\"workers: {workers}\")\n", + "print(f\"averate: {result}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ + "#4\n", + "\n", + "rus = {'One' : 'Один', 'Two' : 'Два', 'Three' : 'Три', 'Four' : 'Четыре'}\n", + "translater = []\n", + "with open('file3.txt', 'r') as f:\n", + " for i in f:\n", + " i = i.split(' ', 1)\n", + " translater.append(rus[i[0]] + ' ' + i[1])\n", + "\n", + "with open('translater.txt', 'w+') as f2:\n", + " f2.writelines(translater)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Введите цифры через пробел \n", + "12 34\n", + "46\n" + ] + } + ], + "source": [ + "#5\n", + "\n", + "with open('file4.txt', 'w+') as f:\n", + " line = input('Введите цифры через пробел \\n')\n", + " f.writelines(line)\n", + " my_numb = line.split()\n", + " print(sum(map(int, my_numb)))" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "invalid literal for int() with base 10: '—'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mline\u001b[0m \u001b[1;32min\u001b[0m \u001b[0minit_f\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[0msubject\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlecture\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mpractice\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlab\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mline\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msplit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m \u001b[0msubj\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0msubject\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlecture\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpractice\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlab\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 8\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34mf'Общее количество часов по предмету - \\n {subj}'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mValueError\u001b[0m: invalid literal for int() with base 10: '—'" + ] + } + ], + "source": [ + "#6\n", + "\n", + "subj = {}\n", + "with open('file5.txt', 'r') as f:\n", + " for line in f:\n", + " subject, lecture, practice, lab = line.split()\n", + " subj[subject] = int(lecture) + int(practice) + int(lab)\n", + " print(f'Общее количество часов по предмету - \\n {subj}')" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Прибыль средняя - 4250.00\n", + "Прибыль каждой компании - {'firm_1': 5000, 'firm_2': 3500, 'средняя прибыль': 4250}\n", + "Создан файл с расширением json со следующим содержимым: \n", + " {\"firm_1\": 5000, \"firm_2\": 3500, \"\\u0441\\u0440\\u0435\\u0434\\u043d\\u044f\\u044f \\u043f\\u0440\\u0438\\u0431\\u044b\\u043b\\u044c\": 4250}\n" + ] + } + ], + "source": [ + "#7\n", + "\n", + "import json\n", + "profit = {}\n", + "pr = {}\n", + "prof = 0\n", + "prof_aver = 0\n", + "i = 0\n", + "with open('file6.txt', 'r') as f:\n", + " for line in f:\n", + " name, firm, earning, damage = line.split()\n", + " profit[name] = int(earning) - int(damage)\n", + " if profit.setdefault(name) >= 0:\n", + " prof = prof + profit.setdefault(name)\n", + " i += 1\n", + " if i != 0:\n", + " prof_aver = prof / i\n", + " print(f'Прибыль средняя - {prof_aver:.2f}')\n", + " else:\n", + " print(f'Прибыль средняя - отсутсвует. Все работают в убыток')\n", + " pr = {'средняя прибыль': round(prof_aver)}\n", + " profit.update(pr)\n", + " print(f'Прибыль каждой компании - {profit}')\n", + "\n", + "with open('file_7.json', 'w') as js:\n", + " json.dump(profit, js)\n", + "\n", + " js_str = json.dumps(profit)\n", + " print(f'Создан файл с расширением json со следующим содержимым: \\n '\n", + " f' {js_str}') " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}