Python Loop Some Coding Questions Leetcode Problem 9