What if planet Earth was made of Lego?

In this blog post we will use a Python script to work out how many lego bricks would be needed to build planet Earth!

To solve our problem we will use the following data:
planet-Earth-lego-brick

We will work out the number of lego bricks needed in several step using a sequencing algorithm: An algorithm consisting of instructions that are carried out (performed) one after another.
sequencing-label
We will use the following steps:

  1. Convert all measurement to the same unit (e.g. mm)
  2. Calculate the volume of planet Earth
  3. Calculate the volume of a lego brick
  4. Number of bricks needed = volume of planet Earth / volume of a lego brick

We will need to use the following two formulas:
volume-sphere-cuboid

The complete flowhchart for our algorithm:
what-if-planet-earth-was-made-of-lego-flowchart

Python Code


You can now code this algorithm using Python to reveal the answer to the initial question: how many lego bricks are needed to build planet Earth!

Number of lego bricks


If you have completed this algorithm, the final answer should be approximatively:
≈ 4.23 x 1026 (in standard form)

≈ 423,000,000,000,000,000,000,000,000 lego bricks!

Using subroutines


It is good practice to use subroutines whenever possible as these can then easily be reused in other programs. Your task is to adapt your code by defining a d using two functions as follows:

  1. Your first subroutine should be called getVolumeOfSphere(), take one parameter called radius and apply the relevant formula to calculate and return the volume of a sphere based on the given radius.
  2. Your second subroutine should be called getVolumeOfCuboid(), take three parameters called width, length and height and apply the relevant formula to calculate and return the volume of a cuboid based on the given dimensions.
unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Did you like this challenge?

Click on a star to rate it!

Average rating 4 / 5. Vote count: 44

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: