fork download
  1. class Point:
  2. def __init__(self,x,y):
  3. self.x = float(x)
  4. self.y = float(y)
  5.  
  6. class Circle:
  7. def __init__(self, x, y, R):
  8. self.O = Point(x,y)
  9. self.R = float(R)
  10.  
  11. def sqrt(n):
  12.  
  13. x = n
  14. y = 1.0
  15. e = 0.00001
  16. while x-y>e:
  17. x = (x + y) / 2
  18. y = n / x
  19. return x
  20.  
  21. def sqr(x):
  22. return x*x
  23.  
  24. def computeDistance(p,p1):
  25. return sqrt(sqr(p1.x-p.x) + sqr(p1.y-p.y))
  26.  
  27. def belongTo(circle, point):
  28. if computeDistance(circle.O, point) < circle.R:
  29. return True
  30. else:
  31. return False
  32.  
  33.  
  34. def main():
  35. n = int(input("Introduceti numarul de cercuri N = "))
  36. C = []
  37. print("Introduceti cercurile: ")
  38. for i in range(1, n+1):
  39. print("Circle#%d"%i)
  40. x = float(input("x="))
  41. y = float(input("y="))
  42. r = float(input("R="))
  43. circle = Circle(x,y,r)
  44. C.append(circle)
  45.  
  46. for i in C:
  47. print(i.O.x, i.O.y,i.R)
  48. print("Introduceti punctul P(x,y)")
  49. x = float(input("x="))
  50. y = float(input("y="))
  51. P = Point(x,y)
  52.  
  53. for i in range(0, n):
  54. if belongTo(C[i], P) is True:
  55. print("The Point(%.3f,%.3f) Belongs To Circle#%d(%.3f,%.3f,%.3f)"%(P.x, P.y, i+1,C[i].O.x, C[i].O.y,C[i].R))
  56. main()
  57.  
Success #stdin #stdout 0.04s 9836KB
stdin
3
1.23
3.4
3.67
0
1.2
2.34
-1.23
8.9
2.34
1.56
2.34
stdout
Introduceti numarul de cercuri N = Introduceti cercurile: 
Circle#1
x=y=R=Circle#2
x=y=R=Circle#3
x=y=R=1.23 3.4 3.67
0.0 1.2 2.34
-1.23 8.9 2.34
Introduceti punctul P(x,y)
x=y=The Point(1.560,2.340) Belongs To Circle#1(1.230,3.400,3.670)
The Point(1.560,2.340) Belongs To Circle#2(0.000,1.200,2.340)