From 99b56b295e9dc1845e460573c21c7c89d0edc68e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D1=83=D0=B7=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=9F=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=BE?= <124675990+CrazyDuck192@users.noreply.github.com> Date: Tue, 21 Mar 2023 19:55:19 +0200 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BB=D0=B0=D1=81=D0=BD=D0=B0=20=D1=80?= =?UTF-8?q?=D0=BE=D0=B1=D0=BE=D1=82=D0=B0=20=E2=84=963?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit №12.1, 12.3, 12.4, 12.5, 12.21, 12.29 --- 12.21.txt | 7 ++ 12.29.txt | 5 ++ 12.4.txt | 31 +++++++++ classwork3.2.py | 97 ++++++++++++++++++++++++++ classwork3.py | 182 ++++++++++++++++++++++++++++++++++++++++++++++++ classwork3.txt | 1 + 6 files changed, 323 insertions(+) create mode 100644 12.21.txt create mode 100644 12.29.txt create mode 100644 12.4.txt create mode 100644 classwork3.2.py create mode 100644 classwork3.py create mode 100644 classwork3.txt diff --git a/12.21.txt b/12.21.txt new file mode 100644 index 0000000..522758b --- /dev/null +++ b/12.21.txt @@ -0,0 +1,7 @@ +12.05.2001 +07.10.1999 +21.11.2007 +05.05.1988 +17.12.1995 +01.07.2000 +05.06.2007 \ No newline at end of file diff --git a/12.29.txt b/12.29.txt new file mode 100644 index 0000000..683bbb0 --- /dev/null +++ b/12.29.txt @@ -0,0 +1,5 @@ +1 : ( 0 , 0 ), ( 10 , 5 ) +2 : ( -2 , 4 ), ( 6 , 6 ) +3 : ( 1 , 5 ), ( 5 , 6 ) +4 : ( -4 , -4 ), ( -2 , -2 ) +5 : ( -10 , 0 ), ( -5 , 3 ) \ No newline at end of file diff --git a/12.4.txt b/12.4.txt new file mode 100644 index 0000000..653cccf --- /dev/null +++ b/12.4.txt @@ -0,0 +1,31 @@ +0.282571031647431 +0.20747292848594728 +0.10626211359387236 +0.05508497026102549 +0.03899772323117452 +0.027234641586775507 +0.019700517494515287 +0.015420632930758982 +0.012189487967336588 +0.00987790154445385 +0.00818927686802249 +0.006878076398963644 +0.0058684945340055535 +0.005065078184055967 +0.004406451915874586 +0.003881209593996607 +0.003439416960531805 +0.0030651994617201255 +0.0027553790609793957 +0.002487152664488468 +0.0022562174851901637 +0.0020567208477062253 +0.0018818174878085672 +0.0017287272357746257 +0.001593572269230383 +0.0014730930226836882 +0.0013666148033738728 +0.0012709194205720842 +0.0011845558093861255 +0.0011073942810778921 +0.0010371877975311303 diff --git a/classwork3.2.py b/classwork3.2.py new file mode 100644 index 0000000..5f9d49b --- /dev/null +++ b/classwork3.2.py @@ -0,0 +1,97 @@ +# Завдання 12.21 +print('Завдання 12.21') + +def dates(filename): + f = open(filename) + d = f.readlines() + d_list = [] + + for x in d: + d_list.append(x.strip().split('.')) + f.close() + + return d_list + +def task_a(d_list): + years = [] + + for date in d_list: + years.append(int(date[2])) + + return min(years) + +def task_b(d_list): + spring_months = ['03', '04', '05'] + spring_dates = [] + + for date in d_list: + if date[1] in spring_months: + spring_dates.append(date) + + return spring_dates + +def task_c(d_list): + year = max([int(x[2]) for x in d_list]) + d = [] + + for date in d_list: + if int(date[2]) == year: + d.append(date) + d_list = d + if len(d_list) == 1: + return d_list[0] + + month = max([int(x[1]) for x in d_list]) + d = [] + + for date in d_list: + if int(date[1]) == month: + d.append(date) + d_list = d + if len(d_list) == 1: + return d_list[0] + + day = max([int(x[0]) for x in d_list]) + d = [] + for date in d_list: + if int(date[0]) == day: + d.append(date) + return d[0] + +filename = 'exercises/12.21.txt' +d_list = dates(filename) + +print(f'Найменший рік: {task_a(d_list)}\n') + +print('Весняні дати: ') +for x in task_b(d_list): + print('.'.join(x)) + +print(f'\nНайпізніша дата: {".".join(task_c(d_list))}') + +# Завдання 12.29 +print('\nЗавдання 12.29') + +def search_rect(filename): + f = open(filename) + rects = f.readlines() + rects_dict = {} + area_dict = {} + + for rect in rects: + rects_dict[int(rect.split()[0])] = ((int(rect.split()[3]), int( rect.split()[5])), + (int(rect.split()[8]), int(rect.split()[10]))) + + for number, coords in rects_dict.items(): + area = abs(coords[0][0] - coords[1][0]) * abs(coords[0][1] - coords[1][1]) + area_dict[number] = area + f.close() + + area = max(area_dict.values()) + for k, v in area_dict.items(): + if v == area: + return (k, v) + + +filename = 'exercises/12.29.txt' +print(f'Прямокутник під номером {search_rect(filename)[0]} має площу {search_rect(filename)[1]}') \ No newline at end of file diff --git a/classwork3.py b/classwork3.py new file mode 100644 index 0000000..4919f59 --- /dev/null +++ b/classwork3.py @@ -0,0 +1,182 @@ +from math import tan +# Завдання 12.1 +print('Завдання 12.1\n') + +def calculate(x, filename): + f = open(filename) + nums = f.readline().split() + coef = len(nums) - 1 + s = 0 + + for a in nums: + s += int(a)*x**coef + coef -= 1 + f.close() + + return s + +def diff(n, x, filename): + f = open(filename) + nums = f.readline().split() + coef = len(nums) + s = 0 + + for _ in range(n): + for i in range(coef): + coef -= 1 + nums[i] = int(nums[i]) * coef + if nums[i] == 0: + del nums[i] + coef = len(nums) + + coef = len(nums) - 1 + for a in nums: + s += a*x**coef + coef -= 1 + f.close() + + return nums, s + +filename = 'exercises/classwork3.txt' +s = calculate(3, filename) +print(f'Значення многочлена у точці 3: {s}') + +df, s = diff(3, 3, filename) +print(f'Похідна третього порядку: {df}') +print(f'Значення похідної у точці 3: {s}') + + +# Завдання 12.3 +print('\nЗавдання 12.3\n') + +def evens(filename): + f = open(filename) + nums = f.readline().split() + answer = [] + for num in nums: + if int(num) % 2 == 0: + answer.append(int(num)) + f.close() + + return answer + +def squares(filename): + f = open(filename) + nums = f.readline().split() + answer = [] + for num in nums: + if int(num) > 0: + if int(num) % 2 != 0 and int(num)**0.5 == int(int(num)**0.5): + answer.append(int(num)) + f.close() + + return answer + +def difference(filename): + f = open(filename) + nums = f.readline().split() + even = [] + odd = [] + for num in nums: + if int(num) % 2 == 0: + even.append(int(num)) + else: + odd.append(int(num)) + f.close() + + return max(even) - min(odd) + +def sequense(filename): + f = open(filename) + nums = f.readline().split() + length = len(nums) + seq = [] + answer = 1 + + for i in range(length-1): + seq.append(nums[i]) + j = i + while True: + if nums[j+1] <= nums[j]: + if len(seq) >= answer: + answer = len(seq) + break + seq.append(nums[j+1]) + j += 1 + seq = [] + f.close() + + return answer + +s = evens(filename) +print(f'Усі парні числа: {s}') + +s = squares(filename) +print(f'Усі квадрати непарних чисел: {s}') + +s = difference(filename) +print(f'Різниця між максимальним парним та мінімальним непарним числами: {s}') + +s = sequense(filename) +print(f'Довжина найдовшої зростаючої послідовносі: {s}') + +# Завдання 12.4 + +def array_1(filename, i): + f = open(filename, 'w') + f.write(' '.join(str(j) for j in range(1, i+1))) + f.close() + +def array_2(filename, i): + f = open(filename, 'w') + f.write(' '.join(str(j**2) for j in range(1, i+1))) + f.close() + +def array_3(filename, i): + f = open(filename, 'w') + nums = [] + + for j in range(1, i+1): + num = 1 + while j != 0: + num *= j + j -= 1 + nums.append(num) + f.write(' '.join(str(x) for x in nums)) + f.close() + +def array_4(filename, i): + f = open(filename, 'w') + f.write(' '.join(str(2**(j+1)) for j in range(1, i+1))) + f.close() + +def array_5(filename, i): + f = open(filename, 'w') + f.write(' '.join(str(2**j + 3**(j+1)) for j in range(1, i+1))) + f.close() + +filename = 'exercises/12.4.txt' +array_1(filename, 10) +array_2(filename, 15) +array_3(filename, 8) +array_4(filename, 6) +array_5(filename, 7) + +# Завдання 12.5 +def func(filename, eps): + f = open(filename, 'w') + nums = [] + j = 0 + x = 1 + + while True: + j += 1 + x = (j-0.1)/(j**3 + abs(tan(2*j))) + if abs(x) < eps: + break + nums.append(x) + for x in nums: + f.write(f'{str(x)}\n') + f.close() + +func(filename, 0.001) \ No newline at end of file diff --git a/classwork3.txt b/classwork3.txt new file mode 100644 index 0000000..7d012d5 --- /dev/null +++ b/classwork3.txt @@ -0,0 +1 @@ +2 3 4 9 1 -5 5 25 1 22 4 2 64 1 \ No newline at end of file