Advertisement
makispaiktis

60 Circles

May 3rd, 2019 (edited)
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.25 KB | None | 0 0
  1. import math
  2. import random
  3.  
  4. # 1. Intro
  5. print("******************************************")
  6. print("******************************************")
  7. print("In this programme, I suppose that I have 60 circles. Each circle")
  8. print("can have one of the following radius: r = 0.5 or 1 or 1.5 or 2 or or 2.5 or 3")
  9. print("1. There are 25 circles with radius = 0.5.")
  10. print("2. There are 20 circles with radius = 1.")
  11. print("3. There are  7 circles with radius = 1.5.")
  12. print("4. There are  5 circles with radius = 2.")
  13. print("5. There are  2 circles with radius = 2.5.")
  14. print("6. There is   1 circle  with radius = 3.")
  15. print()
  16. print("We know that the average radius is: ")
  17. correctAverageRadius = (25*0.5 + 20*1 + 7*1.5 + 5*2 + 2*2.5 + 1*3) / 60
  18. print("(25*0.5 + 20*1 + 7*1.5 + 5*2 + 2*2.5 + 1*3) / 60 = " + str(correctAverageRadius))
  19. print("I will try to prove that this value of average radius can be found if I make this experiment: ")
  20. print("I will make many simulations of choosing one random circle, so its radius will be random too.")
  21.  
  22. # 2. Create a list with each radius (25 first elements equal to 0.5, 20 following elements equal to 1, ....)
  23. firstRadius = 0.5
  24. secondRadius = 1
  25. thirdRadius = 1.5
  26. fourthRadius = 2
  27. fifthRadius = 2.5
  28. sixthRadius = 3
  29. list = []
  30. for i in range(25):
  31.     list.append(firstRadius)
  32. for i in range(20):
  33.     list.append(secondRadius)
  34. for i in range(7):
  35.     list.append(thirdRadius)
  36. for i in range(5):
  37.     list.append(fourthRadius)
  38. for i in range(2):
  39.     list.append(fifthRadius)
  40. list.append(sixthRadius)
  41.  
  42.  
  43. # 2. Ask the user how many choices/simulations to run
  44. simulations = int(input("Enter how many simulations would you like me to run (prefer to be a big number such as 10000): "))
  45. sum = 0
  46. for i in range(simulations):
  47.     randomIndex = random.randint(1, 60)          # Create a number from 1 to 60 (1 <= r <= 60)
  48.     sum += list[randomIndex-1]                   # The randomIndex which is generated is the index of the list
  49.                                                  # and the index of the list is related to the different values of radius
  50. averageRadius = sum / simulations
  51. print()
  52. print("Average radius: " + str(averageRadius))
  53. error = abs(averageRadius - correctAverageRadius)
  54. print("Error: " +  str(100 * error) + "%.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement