Python. Compiler App link
Write a program printing stars " * " in Printing Stars in Reverse pyramid Shape program
Explanation :
hello guys and welcome to Python
programming tutorials by kriisheditz in the
previous tutorial we discussed about how
to print stars in the pyramid shape
today in this tutorial we are discussing
about how to can star in this pattern
that is reverse of that pyramid shape
here is the code first we are asking the
user to enter the number of rows this
for loop is to print rows and inside
that for loop body we can see two other
for loop one is to bring to space and
another is to print star here this is
called as gross and this is called as
column right and here in the column we
can see in some places we need to print
stars in some place we need to print
space for that we are using tree follow
one is to bring close and another is to
print star and another one is to print
space okay now we will see how this code
will work first we are asking user to
enter the number of rows and number of
rows is an integer values so here we use
int function for example we'll take
number value as four okay next we can
see the for loop for I in range now 0
and minus 1 and this for loop is to
print fro the before going to that in
the range function till now we use start
and end right
that is if I want to paint the values
from 1 to 10 then I'll mention 1 and 11
here here 1 is to start and 11 is the N
value so it will give continuous value
from 1 to 10 but if you want to print
the continuous odd number from 1 to 10
then also you can use this range
function by mentioning step here that is
the another parameter to animation step
that is I want 1 3 5 7 9 so here I
mention step as to
and I'll bring this value and here we
can see one three five seven nine
continuous odd numbers by default this
step value will be 1 that means if they
didn't mention this step then it will
take 1 so it will print continuous
number okay here is an another example
here why is the starting value 0 is the
ending value and minus one is two steps
value that means I want to print the
value from five four three two one and
here we can see the values now here
we'll come back to our code okay here
for I in range now zero minus one minus
one is step numbers to starting values
zero is the ending value so if the value
of num is four then it will give four
three two one here we can see here I
value will be four here three here too
and here one then we will go to the jet
loop here ranges from zero to num - I
share num - I because here in the first
row we can see zero space like and in
the second line we can see one here
third line - and the last line free
space if you go for the num - I number
value is 4 y value is 4 so 4 - 4 0 space
here number is four Y value is 3 4 - 3 1
space 4 - 2 to stage 4 - 1 3 space this
for loop is to bring space and the next
4 look into pink star that is comes 0 -
I initially I value in before so I want
to prank for star here next I value will
be 3 so here 3 star I value B - yes to
star I value will be 1 and here 1 start
ok so here we use range from
zero - I okay now we'll run the score so
I went a number of rows s4 and here we
can see the output okay in our program
first we are asking the user to enter
the number of rows and the value will be
stored in the variable num for example I
enter the value as four okay so num
value will before and next control goes
to the for loop I in range num - 0 minus
1 here non-value is 4 and the step is
minus 1 so it will give the I value as 4
3 2 1 so I value will be 4 3 2 & 1
okay first I value Delta for control
goes to the gate for loop here ranges
from 0 to num - I that means
num well you spot and I value is 4 that
is range from 0 to 0 so this print
statement will not execute and control
goes to the next for loop here ranges
from 0 to I a value is 4 so 0 to 4 that
means it will give value as 0 1 2 3
first J value will be 0 it will go to
the print statement and it will print
star so here we can see the star okay
next in this space so here space and
control goes to here and now J value
will be incremented to 1 and again print
statement will execute so it will print
another star and end it space so control
is here again control goes to the J loop
J value will be 2 now and it will
execute the print statements so here
star nd space and control is here now J
value in 2 3
and print statement will execute so it
will print star here after this it will
come out of this print statement and it
will execute this print that is nothing
but control goes through here there is
next line next again control goes to the
main for loop
I value was for now I value is three and
it will execute this first for loop
ranges from zero to num - ID number is
for high value three so it will give
value as 0 so J value is 0 no so it will
execute this print statement that is in
this space so we can see here space and
control goes to here next control comes
to the next for loop J in the range from
0 to I value is 3 so this print
statement will execute twice first J
value will be 0 in this space next J
value will be 1 space and next J value
will be 2 it will execute trice after
this it will come out of this loop and
it will execute this print statement so
control goes to the next line here
control goes to the main for loop
previously a value of 3
now I values will be 2 and it will go to
the first for loop it is range from 0 to
num - I number is for high value is - 4
-2 various ranges from 0 to 2 so it will
give value as 0 and 1 that means this
print statement will execute life so
here we will get to space after
executing this print statement it will
come out of this loop and it will go to
the next for loop ranges from 0 to I
value is 2 so this print statement will
execute twice so control is here now so
it will print star ended space and next
again sorry stinking next after
executing twice it will come out of this
loop and it will execute next print
statement that means control is here now
control again goes to the main for loop
previously I value of two now I value is
one and here it will execute first for
loop ranges from zero to num - I number
is for a value is 1 so 4 minus 1 that is
free so ranges from 0 to 3 that means 0
1 2 this print statement will execute
price so here we'll get 3 space after
that it will come out of this loop and
it will go to the next four ranges from
0 I either use 1 that means 0 to 1 so it
will give value as 0 so this print
statement will execute 1 so it will
print star here after that it will come
out of this loop and it will go to the
print statement so control goes to the
next line next control again go to the
main for loop here this range function
will give the value as 4 3 2 1
these values are already executed so it
will come out of this loop so here
execution completed and because we
decide output okay that's it for now
thank you for watching don't forget to
subscribe my channel I will make your
next class till then I guess
Video tutorial to this program
Program :
num=int(input("enter the number of rows :"))
for i in range(num,0,-1):
for j in range(0,num-i):
print(end=" ")
for j in range(0,i):
print("*",end=" ")
print()
Output :
enter the number of rows :27
* * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * * *
* * * * * * * * * *
* * * * * * * * *
* * * * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
[Program finished]
For more program
0 Comments
à°®ీà°•ు edit à°šేà°¸ి à°«ొà°Ÿోà°¸్, à°µీà°¡ిà°¯ోà°¸్, à°‡ంà°•ా à°¦ెà°¨ి à°—ుà°°ింà°šి à°…à°¨్à°¨ా ఇన్à°«à°°్à°®ేà°·à°¨్ à°•ాà°µాà°²ీ à°…ంà°Ÿే Plz comment à°šేà°¯ంà°¡ి