Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. from random import randint
  2. import matplotlib
  3. import matplotlib.pyplot as plt
  4.  
  5. xa = []; ya = []; xb = []; yb = []; xc = []; yc = []; xd = []; yd = []; xe = []; ye = []; xf = []; yf = []
  6.  
  7. def experiment(N):
  8. A = B = C = D = E = F = 0
  9. for i in range(N):
  10. x = randint(0, 60)
  11. y = randint(0, 60)
  12. if (0 <= abs(x-y) <= 15):
  13. A += 1
  14. xa.append(x)
  15. ya.append(y)
  16. if ((y-x) >= 15) or ((x-y) >= 15):
  17. B += 1
  18. xb.append(x)
  19. yb.append(y)
  20. if (y >= x) and ((y-x) <= 15):
  21. C += 1
  22. xc.append(x)
  23. yc.append(y)
  24. if (y > 30 or x > 30) and (abs(y-x) <= 15):
  25. D += 1
  26. xd.append(x)
  27. yd.append(y)
  28. if (y-x) > 15:
  29. E += 1
  30. xe.append(x)
  31. ye.append(y)
  32. if (y > 55 or x > 55) and (abs(y-x) <= 15):
  33. F += 1
  34. xf.append(x)
  35. yf.append(y)
  36.  
  37. result = [A/N, B/N, C/N, D/N, E/N, F/N]
  38. return result
  39.  
  40. print("Answer:")
  41. print(experiment(100000))
  42. x = [i for i in range(1, 1000, 100)]
  43. y = []
  44. for i in range(1, 1000, 100):
  45. y.append(experiment(i)[0]) #A
  46. """
  47. plt.plot(x[2:], y[2:])
  48. plt.title('PLOT')
  49. plt.show()
  50. """
  51. xmin, xmax, ymin, ymax = plt.axis([0, 60, 0, 60])
  52. plt.plot(xa, ya, linestyle="", marker="o")
  53. plt.title('P(A)')
  54. plt.show()
  55.  
  56. xmin, xmax, ymin, ymax = plt.axis([0, 60, 0, 60])
  57. plt.plot(xb, yb, linestyle="", marker="o")
  58. plt.title('P(B)')
  59. plt.show()
  60.  
  61. xmin, xmax, ymin, ymax = plt.axis([0, 60, 0, 60])
  62. plt.plot(xc, yc, linestyle="", marker="o")
  63. plt.title('P(C)')
  64. plt.show()
  65.  
  66. xmin, xmax, ymin, ymax = plt.axis([0, 60, 0, 60])
  67. plt.plot(xd, yd, linestyle="", marker="o")
  68. plt.title('P(D)')
  69. plt.show()
  70.  
  71. xmin, xmax, ymin, ymax = plt.axis([0, 60, 0, 60])
  72. plt.plot(xe, ye, linestyle="", marker="o")
  73. plt.title('P(E)')
  74. plt.show()
  75.  
  76. xmin, xmax, ymin, ymax = plt.axis([0, 60, 0, 60])
  77. plt.plot(xf, yf, linestyle="", marker="o")
  78. plt.title('P(F)')
  79. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement