Kepler Group Interview Question

How would the python language for this look like?