The question along with the solution is posted. But i didn't understand the solution, especially inside the for loop. Can someone elaborate the code for me?
[1]: https://i.stack.imgur.com/p1Lkp.jpg
here I try to put in some explanations for the problem you posted.
Actually, it's easier if you can run it through the platform to see the program in action - http://pythontutor.com/ next time.