Advertisement
kxcoze

tanya_makoha_lab_2

Apr 21st, 2021
903
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1.  
  2.  
  3. def intersection_check(k1, b1, k2, b2):
  4.     if k1 != k2:
  5.         x = (b2-b1) / (k1-k2)
  6.         y = k1*x + b1
  7.         return round(x, 3), round(y, 3)
  8.     return None
  9.  
  10.  
  11. n = int(input("Введите кол-во прямых: "))
  12. all_lines = []
  13.  
  14. print(f"Введите {n} прямых, задав 'y = kx + b' их коэффициенты - k, b (через пробел):")
  15. for _ in range(n):
  16.     k, b = [float(x) for x in input().split()]
  17.     all_lines.append((k, b))
  18.  
  19. all_intersections = set()
  20. for checked_ind, checked_line in enumerate(all_lines):
  21.     for ind, line in enumerate(all_lines):
  22.         if ind != checked_ind:
  23.             result = intersection_check(*checked_line, *line)
  24.             if result is not None:
  25.                 all_intersections.add(result)
  26.  
  27. """
  28. Для просмотра множества точек пересечения
  29. print(all_intersections)
  30. """
  31.  
  32. print("Точек пересечения:", len(all_intersections))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement