Welcome to Project Lovelace! We're still in early development so there are still tons of bugs to find and improvements to make. If you have any suggestions, complaints, or comments please let us know on Discourse, Discord, or GitHub!

Speed of Light

You will learn about: light is fast.

Light is really fast: 299,792,458 meters per second to be exact. That's fast enough to make it almost 7.5 times around the Earth in one second! A spacecraft would take a few days to reach the Moon, but a beam of light could do it in 1.255 seconds.

We can calculate how long it takes a beam of light to reach places in space. Since light travels at a constant speed $c$, the time $t$ it takes to travel a distance $d$ is $t = d/c$. Try to submit some code with a function light_time(distance) that returns the time it takes light to travel that distance.

Input: A distance in meters (m).

Output: The time it takes for light to travel the input distance, in seconds (s).

Example 1

Input distance: 376291900 Output time: 1.255175

Example 2

Input distance: 299792458 Output time: 1.0
 Difficulty  Timesink
 Function light_time(distance)

You must be logged in to view your submissions.


Earth-Moon-Mars distances to scale, at LIGHT SPEED!, James O'Donoghue
Watch a beam of light travel to Mars and back to Earth in real-time.
Powers of Ten: A Film Dealing with the Relative Size of Things in the Universe and the Effect of Adding Another Zero (1977), Charles and Ray Eames
There are also interactive versions: The Scale of the Universe and Universcale. The original book is also online: Cosmic View: The Universe in 40 Jumps.


  • The speed of light is usually denoted by lowercase $c$, apparently for "constant" or from the Latin celeritas meaning quickness or swiftness.
  • Light takes 1.255 seconds to travel from the surface of the Earth to the surface of the Moon. The average distance between the Earth and Moon is 384,400 km but the radius of the Earth is 6,371 km and the radius of the Moon is 1,737 km, so in this case light actually travels 384,400 - 6,371, - 1,737 = 376,292 km.
  • The first measurement of the speed of light was made in 1676 by Ole Rømer but scientists argued about whether the speed of light was finite or infinite for a long time.

Let us know what you think about this problem! Was it too hard? Difficult to understand? Also feel free to discuss the problem, ask questions, and post cool stuff on Discourse. You should be able see a discussion thread below. Would be nice if you don't post solutions in there but if you do then please organize and document your code well so others can learn from it.