Log in to save your progress.
<< Back to problems
Note! The window is too narrow to use Pythonlab.dev. Use a device with a keyboard!

Estimate pi using random numbers

Prerequisites: Basic course part I

Your task is to estimate the value of pi using a circle inscribed in a square. Imagine that you are randomly generating points within the square below. Most points will fall within the circle, while some will fall outside of it. Use this to make an estimate of pi.

The program takes an integer as input: The number of points n to be randomized.

Example input 1

10

Example output 1

3.2

Example input 2

10000

Example output 2

3.1544

Note that the "Example output" does not have to be exact because random numbers are involved. But you should see that the approximate value of pi gets better with larger n.

Login to save your progress and your code.

Create

Write your code here. Click "Mark as done" when you have solved the task.

-- Output from your program will be here --