Computer Science, asked by Anonymous, 8 hours ago

Print this pattern for python

* * * * *
* * * *
* * *
* *
*
Also tell how you do it​

Answers

Answered by Anonymous
5

Method 1 :-

for i in reversed(range(1,6)) :

‎ ‎ ‎print ("* "*i)

Method 2 :-

for i in range(5,0,-1):

‎ ‎ ‎print ("* "*i)

Explanation :-

In this question we have to print stars in decreasing order starting from 5 and ending at 1. For this task, we have to create a loop which will run reversely from 5 to 1 and we can print stars times the loop value.

We can reverse a loop by 2 methods. Firstly by using reversed() function which can be used to reverse the order of loop. Another method is stepping. range function can take 3 arguments where first argument is starting point, 2nd is ending point and the third is step. This third argument is optional, by default step value is 1.

That's all about this pattern.

Similar questions