Python. Compiler App link
Write a program printing stars " * " in Printing Stars in pyramid Shape program
Explanation :
hello guys and welcome to Python
programming kriisheditz tutorials by a most
economies today in this tutorial we are
discussing about how to write programs
to get output like this that is we want
to think tasks in the pyramid shape or
triangle shape okay this is the code to
print stars in the pyramid shape here
first we are asking the user to enter
the number of rows that is for example
here we can see this star pyramid
contains 4 rows 3 is 1 2 3 and 4 right
so here num value is full so here we are
asking the user to first enter the
number of rows after that we can see the
for loop and here I is a variable and
this for loop is 4 rows okay and here we
can see the range function zero to none
suppose if we enter number of rows is 4
then brain function is 4 0 to 4 then it
will give the output as 0 1 & 2 & 3 I is
equal to 0 for this row 1 is for this so
2 is for this row and 3 is for this room
ok next in the column that is here we
can see space and start that is in some
places we need to bring space and in
some places we need to print star ok so
here we are using 2 for loop that is the
first follow - pink space and the second
for loop is to print star and here we
can see in the first for loop J is a
variable and ranges from 0 to num - I
minus 1 here we can see number Ally is 4
right and here we can see the T space
here
after that we can see the star here long
value is 4 and I value is 0 and minus 1
that will give 3
so here this statement will print price
so here we can see three space here
I value is 1 so 4 minus 1 minus 1 so it
will give 2 so we can see 2 space here I
values 2 so 4 minus 2 minus 1 so answer
is 1 so here we can see the 1 space now
after executing this statement price
control goes to the next for loop and
here we can see the range from 0 to I
plus 1 initially I value will be 0 so 0
to 1 that means it will give the value
as 0 so it will execute 1 so in the
first line we can see the fingerstyle
next it will come out of this loop and
you can print this statement that means
control goes to the next line
okay this is about the core here first
we are asking the user to enter the
number of rows then this for loop is for
growth that is 0 two numbers in the main
core look we can see 2 4 looks that is
one is for to print space and another is
to print star now we'll run this program
I'll enter number of rows is 5 and here
we can see the pyramid okay now we will
see how this code will work first we are
asking the user to enter the number of
rows for example we will take number is
4 now so control goes to this for loop I
use a variable here range 0 to num will
give 4 values again it is 0 1 2 3
fine and next it will go to the J loop
and here range is from 0 to num - I
minus 1 actually number give us 4 and
here I value 0 so 4 minus 0 minus 1 so
it will you 3 so he arranges from 0 to 3
so it will give the answer as 0 1 & 2
right so first J value will be 0
one two so here it will print space and
again be control goes to the for loop
now say value will be one and again this
print statement will execute so again
space again the control goes to the J
loop now J value is two so again it will
clean space now control is here now
control comes out of this loop and it
will go to the next for loop that ranges
from zero to I plus 1 so I'll and u is 0
so 0 to 1 that means it will give value
as 0 so here J value will be 0 so it
will go to the print statement and it
will print star here but here range
gives only one value it is already
executed so it will come out of this
loop and it will go to the next
statement that is print statement so
control goes to the next line here okay
next again it goes to the main power
loop and now I value is the one so again
control comes to this first for loop and
ranges from 0 to num minus I minus 1
number value was for I values one now
minus 1 so it will do too okay so here
ranges from 0 to 2 that means 0 and 1 so
it will print to space here okay after
executing this for loop it will come to
the next for loop and it will print star
here 0 to I plus 1 that means either use
1 so 0 to 2 so it will give value as 0
and 1 and so first print star so it will
print here here in deep space so here we
can see this space and again control
goes to this for loop now this day value
will be 1 and it will bring this star
and control is here now then control
come out of this loop and it will bring
pink statement so control comes
here here in this code if you change
here I change this to two star I plus 1
and I say this and on this and identify
here we can see the star pyramid here we
can see single star three star five star
seven and nine here we can see the odd
number of stars to do that we need to
change here and we can print this star
pyramid using single for loop also that
is here we can see the function pyramid
and it will take the parameter as Road
and inside the function we can see this
follow and I use the variable and ranges
from rows that means it will take zero
two rows and here we can see the print
statement that is it will print space
this much time and it will print star
this time that is this multiplication
symbol is a repeater and here plus
symbol is the concatenation symbol okay
so if you run this code and here I will
call the function from it and I'll pass
the parameter as Phi and test and we can
see the pyramid and this code is similar
to the previous one but here instead of
for loop we are using print statement
okay here if you want you can change
this to John okay now I will say this
and on this I will call the function
pyramid and us as for and here we can
see the output this is the odd number of
stuff okay back before now thank you for
watching don't forget to subscribe my
channel and we can mix last till then
take care.
Video tutorial to this program,
Program :
num=int(input("enter the number of rows :"))
for i in range(0,num):
for j in range(0,num-i-1):
print(end=" ")
for j in range(0,i+1):
print("*",end=" ")
print()
Output :
enter the number of rows :27
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
* * * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * *
[Program finished]
Once again
Output :
enter the number of rows : 5
*
* *
* * *
* * * *
* * * * *
[Program finished]
For more program
0 Comments
à°®ీà°•ు edit à°šేà°¸ి à°«ొà°Ÿోà°¸్, à°µీà°¡ిà°¯ోà°¸్, à°‡ంà°•ా à°¦ెà°¨ి à°—ుà°°ింà°šి à°…à°¨్à°¨ా ఇన్à°«à°°్à°®ేà°·à°¨్ à°•ాà°µాà°²ీ à°…ంà°Ÿే Plz comment à°šేà°¯ంà°¡ి