Habitable exoplanets

Useful to know: if statements, square roots.

An exoplanet is a planet orbiting a star other than our sun and we can actually detect these planets now! It turns out there are a lot of exoplanets and everyone is wondering whether anything lives there. How far the exoplanet is from its host star can determine whether it can support life or not. If it's too close to the star the planet would be too hot for life to survive there. Too far and now it's too cold to support life. There is a sweet spot in between called the circumstellar habitable zone (CHZ) in which a planet's surface is just the right temperature to support liquid water: not too hot and not too cold.

Image credit: The Center for Planetary Science

One simple definition is that the CHZ is a ring around the star (the green zone in the figure) with inner radius $\displaystyle r_i = \sqrt{\frac{L}{1.1}}$ and outer radius $\displaystyle r_o = \sqrt{\frac{L}{0.54}}$. The radii $r_i$ and $r_o$ are given in astronomical units or au (1 au is roughly the distance between the Sun and the Earth) and $L$ is the star's luminosity as a multiple of the Sun's luminosity.

Given a star's absolute luminosity $L$ and the planet's distance from the star $r$ as inputs, return "too hot" if the planet is too close to the star, "too cold" if it's too far away from the star, and "just right" if it's in the CHZ.

Input: The The star's absolute luminosity $L$ and the planet's distance from the star $r$.

Output: The string "too cold" if the planet is too far away, "too hot" if it is too close, or "habitable" if it is within the CHZ.

Example input

(L=1.11, r=1.04)

Example output

just right

You must be logged in to submit code but you can play around with the editor.

You must be logged in to upload code.


  • There are many other conditions for habitability than just distance of an exoplanet from its host star, and there are many different estimates of where the circumstellar habitable zone is for our own solar system.


Kasting, J.F. (1996), Habitable zones around stars: An update. In: Doyle, L. (ed.). Circumstellar Habitable Zones, pp. 117-142.
Gave the boundaries used in this problem but there are other attempts, including many recent ones. We just used this one for simplicity. We could not find the chapter referenced online so we scanned a copy and uploaded it on here.