Can any one explain the logic behind this code

Sorry for asking this very basic question – but I cannot understand why it does what it does.

a = int(input('Enter No. of rows'))
for i in range (a,0,-1):

Thank you taking time to review and answer this question.

>Solution :

The range function accepts three arguments. The first arg. represents the starting integer, the second arg. represents the integer at which to stop, and the 3 arg. represents how much should the numbers increase by. Therefore, in this case, (start, stop, step) = (a, 0, -1). This basically means start from a (the inputted value), move till 0 and increment by -1.

Then, in each iteration, the asterisk symbol (*), repeated i many times, is printed.

You can refer the range function here and here.

Leave a Reply