Pregunta de entrevista de Kepler Group

How would the python language for this look like?