ION Group interview question

Python coding, puzzles from geeks for geeks