Loops Hackerrank Solution In Python