Kepler Group interview question

How would the python language for this look like?