Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- import matplotlib
- import matplotlib.pyplot as plt
- xa = []; ya = []; xb = []; yb = []; xc = []; yc = []; xd = []; yd = []; xe = []; ye = []; xf = []; yf = []
- def experiment(N):
- A = B = C = D = E = F = 0
- for i in range(N):
- x = randint(0, 60)
- y = randint(0, 60)
- if (0 <= abs(x-y) <= 15):
- A += 1
- xa.append(x)
- ya.append(y)
- if ((y-x) >= 15) or ((x-y) >= 15):
- B += 1
- xb.append(x)
- yb.append(y)
- if (y >= x) and ((y-x) <= 15):
- C += 1
- xc.append(x)
- yc.append(y)
- if (y > 30 or x > 30) and (abs(y-x) <= 15):
- D += 1
- xd.append(x)
- yd.append(y)
- if (y-x) > 15:
- E += 1
- xe.append(x)
- ye.append(y)
- if (y > 55 or x > 55) and (abs(y-x) <= 15):
- F += 1
- xf.append(x)
- yf.append(y)
- result = [A/N, B/N, C/N, D/N, E/N, F/N]
- return result
- print("Answer:")
- print(experiment(100000))
- x = [i for i in range(1, 1000, 100)]
- y = []
- for i in range(1, 1000, 100):
- y.append(experiment(i)[0]) #A
- """
- plt.plot(x[2:], y[2:])
- plt.title('PLOT')
- plt.show()
- """
- xmin, xmax, ymin, ymax = plt.axis([0, 60, 0, 60])
- plt.plot(xa, ya, linestyle="", marker="o")
- plt.title('P(A)')
- plt.show()
- xmin, xmax, ymin, ymax = plt.axis([0, 60, 0, 60])
- plt.plot(xb, yb, linestyle="", marker="o")
- plt.title('P(B)')
- plt.show()
- xmin, xmax, ymin, ymax = plt.axis([0, 60, 0, 60])
- plt.plot(xc, yc, linestyle="", marker="o")
- plt.title('P(C)')
- plt.show()
- xmin, xmax, ymin, ymax = plt.axis([0, 60, 0, 60])
- plt.plot(xd, yd, linestyle="", marker="o")
- plt.title('P(D)')
- plt.show()
- xmin, xmax, ymin, ymax = plt.axis([0, 60, 0, 60])
- plt.plot(xe, ye, linestyle="", marker="o")
- plt.title('P(E)')
- plt.show()
- xmin, xmax, ymin, ymax = plt.axis([0, 60, 0, 60])
- plt.plot(xf, yf, linestyle="", marker="o")
- plt.title('P(F)')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement