from math import sqrt
import matplotlib.pyplot as plt
import random
# входные данные
r = float(input('R='))
n = int(input('Количество точек: '))
inside_points = []
outside_points = []
for i in range(n):
x = random.uniform(-r, r)
y = random.uniform(-r, r)
flag = ((x >= -r) and (x < 0) and (y >= sqrt(r**2 - x**2)) or
(x >= 0) and (x <= r) and (y >= -sqrt(r**2 - x**2)) and (y <= 0))
if flag:
inside_points.append((x, y))
else:
outside_points.append((x, y))
fig, ax = plt.subplots()
ax.set_aspect('equal')
ax.set_xlim(-r, r)
ax.set_ylim(-r, r)
ax.scatter(*zip(*inside_points), color='green')
ax.scatter(*zip(*outside_points), color='red')
plt.show()
Программа должна быть построена на основе кода:
from math import *
flag = 0
r = float(input('R='))
x = float(input('X='))
y = float(input('Y='))
if (x < -r) or (x > r):
flag = 0 #False
if ((x>=-r) and (x<0) and (x>=-r) and (y<=r)
and (y>=sqrt(r**2-x**2)) or
(x>=0) and (x<=r) and (-y<=sqrt(r**2-x**2))
and (x<=r) and (y>=-r) and (y<=0)):
flag = 1
else:
flag = 0
print("Точка X={0: 6.2f} Y={1: 6.2f}"
.format(x, y), end=" ")
if flag:
print("попадает", end=" " )
else:
print("не попадает", end=" ")
print("в область.")