Navaera Interview Question

Asked to solve a python program