Consider a unit square with vertices (0, 0), (0, 1), (1, 1), (1, 0). If two points are picked randomly within the square calculate the average distance between them. Hints : You may need to use.........
import random random.uniform(start, stop)
random.uniform(0, 1) --> 0.2967783156262709 random.uniform(0, 1) --> 0.5677612555662909
lst = [0, 1, 2, 3, 4] sum(lst) --> 10
from math import sqrt
sqrt(5) --> 2.23606797749979 sqrt(4) --> 4.0
Monte Carlo method is a very powerful technique to generate interesting results. Now don't get your brain baked on this. This is an extremely simple example of Monte Carlo method and you needn't be familiar with the term at all. Write a program to approximate the value of pi. How to do this using method mentioned above ? Consider a unit square with a unit radius circle in it. If points are randomly chosen in the combined figure some will lie in the circle and others will lie outside it. Now think about how the value of pi can be computed from this information.
Hints : You may need to use.........
import random random.uniform(start, stop)
random.uniform(0, 1) --> 0.2967783156262709 random.uniform(0, 1) --> 0.5677612555662909
If anymore hints are given, it will be like telling you the answer....