From e9208ade043f2304225d1e1150f57fa31aa49c28 Mon Sep 17 00:00:00 2001 From: Andrew Guschin Date: Sun, 4 Apr 2021 21:39:38 +0400 Subject: =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=208,=2010,?= =?UTF-8?q?=2011=20=D0=B7=D0=B0=D0=B4=D0=B0=D1=87=D0=B8=20=D0=BF=D0=BE=20?= =?UTF-8?q?=D0=BF=D0=B8=D1=82=D0=BE=D0=BD=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python-func/Makefile | 23 +++++++++++++++++++++++ python-func/task10.py | 40 ++++++++++++++++++++++++++++++++++++++++ python-func/task11.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ python-func/task8.py | 9 +++++++++ 4 files changed, 120 insertions(+) create mode 100644 python-func/Makefile create mode 100644 python-func/task10.py create mode 100644 python-func/task11.py create mode 100644 python-func/task8.py diff --git a/python-func/Makefile b/python-func/Makefile new file mode 100644 index 0000000..9c2a0c3 --- /dev/null +++ b/python-func/Makefile @@ -0,0 +1,23 @@ +task8: + python3 task8.py +test8: + @printf "" | python3 task8.py + @printf "Answer: \n" + +task10: + python3 task10.py +test10: + @printf "" | python3 task10.py + @printf "Answer: \n" + +task11: + python3 task11.py +test11: + @printf "" | python3 task11.py + @printf "Answer: \n" + +clean: + rm -f *.zip + +archive: clean + zip archive.zip *.py diff --git a/python-func/task10.py b/python-func/task10.py new file mode 100644 index 0000000..8c548e1 --- /dev/null +++ b/python-func/task10.py @@ -0,0 +1,40 @@ +from math import sqrt + + +class Point: + def __init__(self, x: float, y: float): + self.x = x + self.y = y + + +def dist(p1: Point, p2: Point) -> float: + return sqrt((p2.x - p1.x) ** 2 + (p2.y - p1.y) ** 2) + + +def solve(points: list[Point]) -> int: + cnt = 0 + for p1 in points: + for p2 in points: + for p3 in points: + if p1 == p2 or p2 == p3 or p3 == p1: + continue + + a = dist(p1, p2) + b = dist(p2, p3) + c = dist(p3, p1) + + if a + b > c and a + c > b and b + c > a: + cnt += 1 + return cnt + + +n = int(input("Введите количество точек: ")) +points = [] +for i in range(n): + x, y = map(float, input().split()) + p = Point(x, y) + points.append(p) + +res = solve(points) +print(f"Используя введённые точки можно создать {res} треугольников") + diff --git a/python-func/task11.py b/python-func/task11.py new file mode 100644 index 0000000..cd759fd --- /dev/null +++ b/python-func/task11.py @@ -0,0 +1,48 @@ +from math import sqrt + + +class Point: + def __init__(self, x: float, y: float): + self.x = x + self.y = y + + +def dist(p1: Point, p2: Point) -> float: + return sqrt((p2.x - p1.x) ** 2 + (p2.y - p1.y) ** 2) + + +def area_triangle(p1: float, p2: float, p3: float) -> float: + p = (a + b + c) / 2 + return sqrt(p * (p - a) * (p - b) * (p - c)) + + +def solve(a: Point, b: Point, c: Point, d: Point, e: Point) -> float: + ab = dist(a, b) + ac = dist(a, c) + ad = dist(a, d) + ae = dist(a, e) + bc = dist(b, c) + cd = dist(c, d) + de = dist(d, e) + + a1 = area_triangle(ab, bc, ac) + a2 = area_triangle(ac, cd, ad) + a3 = area_triangle(ad, de, ae) + + return a1 + a2 + a3 + + +ax, ay = map(int, input("Ax, Ay = ").split()) +bx, by = map(int, input("Bx, By = ").split()) +cx, cy = map(int, input("Cx, Cy = ").split()) +dx, dy = map(int, input("Dx, Dy = ").split()) +ex, ey = map(int, input("Ex, Ey = ").split()) + +res = solve( Point(ax, ay) + , Point(bx, by) + , Point(cx, cy) + , Point(dx, dy) + , Point(ex, ey) ) + +print(f"Площадь фигуры со введёнными точками равна {res}") + diff --git a/python-func/task8.py b/python-func/task8.py new file mode 100644 index 0000000..923d598 --- /dev/null +++ b/python-func/task8.py @@ -0,0 +1,9 @@ +def digit_sum(n: int) -> int: + return sum(map(int, str(n))) + +print("Счастливые билеты:") +for i in range(100, 1000): + for j in range(100, 1000): + if digit_sum(i) == digit_sim(j): + print(f"{i}{j}") + -- cgit v1.2.3