Python Pattern Programs - Printing Stars '*' in Right Angle Triangle Shape

 Python. Compiler App link


Download



 Write a program printing stars " * " in Right Angle Triangle Shape pattern program ?




Explanation :

hello guys and welcome to Python

programming tutorials by kriisheditz

in the previous tutorial we discussed

about the Python program believes using

the number of rows then we can see the

stars in this particular pattern right

here instead of tasks if you want you

can use alphabets or numbers here if I

want one and I will save this and run

this and if I enter three and here we

can see one manma or instead of this if

you use an alphabet and it will enter

and we can see this pattern right today

in this tutorial we'll discuss another

Python program ladies we want our output

in this form that is single star in the

first line three star in the second line

and five star in the third line that is

we want our number of stars in the

column here we can see there is no

change in the rows but if if you enter

number of rows is five then we will get

Phi root and here there is a change in

the columns so we will see how to write

this pattern program and here I'll ask

the user to enter the input first then

I'll use another variable K and I'll

initialize this to one okay next I'll

use for loop it is four rows so no

change in this one to num plus one

and indicate for loop this is for column

you start from the one and it is still a

plus one

now here I'll faint start and end YZ

space okay now I will come out of this

loop and in the first for loop I'll

write k is equal to k plus 2 and I'll

you think statement for new line ok now

I'll save this annual Dix okay enter the

number of rows and enter 3 and here we

can see the output there is single star

in the first line 3 star in the second

line 5 star in the third line okay okay

now we'll see how our program will work

first here we can see the input

statement that is we are asking the user

to enter the number of rows right so in

this example we enter 3 so null value is

3 after entering the input it will fade

in this variable so now num value is 3

okay after that it will come to this

statement that is k equal to 1 so we

initialize the variable K bits value 1

so value of K is 1 now okay now next it

will come to the for loop as I say this

for loop is 4 rows so I even variable

here and here we took range 1 to num +1

here num is 3 so ranges from 1 to 4

right so what is the output from this 1

2 3 right

and here I will take the first value

that is I equal to one so now I value is

1 okay here I value is 1 now so next it

will enter to the for loop and here

another for loop is to think it is for

column and here Z is an another variable

and here range values 1 to k plus 1 now

k value is 1 so 1 plus 1 is 2 so what is

the outcome from this there is one right

here 1 is included 2 is excluded so it

will give the output as 1 so now J value

is 1 here next it will go to this print

statement and it will paint this number

star or out of it so we will get first

one here okay after that space so here

it will give space now control is here

okay now control again goes to the for

loop okay but in the range we can see

only 1 value is present so it is already

executed so it will come out of this

loop and it will go to the execution of

next statement that is k is equal to k

plus 2 okay at first K value verse 1 now

1 plus 2 now K value in between now

after executing this statement control

will go to the print statement here

nothing is present to display so simply

it will go to the next line

so now control goes to here okay now

again after executing this statement

control goes to remain for loop that is

first for loop now I value will be

incremented and now I value is 2 so here

I value is 2 and range value is same

that is 1/2 num plus 1 and next it will

enter this follow and here you can see

another for loop so it will execute this

for loop now here in this case range

will be change because K

value is not one no K value is free No

so here rain will be 1 2 k plus 1 there

is 1 2 4 okay and the output is 1 2 & 3

right now they will take the first value

that is 1 and it will print this one so

here we caught one

okay next end in space so control goes

to here next again here from this print

to control goes to be this for loop that

is death for loop this value will be

incremented here and it will take the

next value that is 2

okay now this value is 2 and it will go

to this print statement and it will

execute that so here we will get 1 okay

next in this space so control goes to

here and again control goes to this for

loop and now J is incremented to 3 so

now say value is 3 okay so again it will

go to the print statement and it will

write 1 here okay and now control goes

to here it is in this space type control

is here after this control will again go

to this for loop but here range is from

1 to 4 that is 1 2 3 so it will come out

of this loop and control goes to this

statement that is k is equal to k plus 2

so now k value will be incremented

actually K value is 3 so 3 plus 2 now it

will become fine and next it will go to

this statement and it will print that

means it will go to the next line

control was here after executing print

statement control goes to here there is

next line now again here control goes to

the for loop previously I value as to

normal

it will be incremented to three so now

the I value is 3 here then it will go to

this four loop here range is 1 to k plus

1 now k value is 5 so this is 1 to 6 so

it will give 1 2 3 4 & 5

okay now first J value is 1 it will go

to this print statement and it will

bring this one here and now space so

control goes to here now control will

again goes to this for loop and now they

will be incremented to to lose their

value will be 2 and it will again go to

this print statement and it will pink

one and anglish space so control goes to

here now again control goes to this for

loop and here J is incremented from 2 to

3 now J value is 3 and it will go to

this print statement and it will print 1

here now control this here again the

control goes to this for loop now J

value will be incremented to 4 so their

value is 4 here so again it will go to

the print statement and it will pink one

and control is here now

now again control goes to this for loop

I know J value is 5 so it will go to

this print and it will print and control

is here now okay now again control goes

to this for loop and here all the values

are executed for it will come out of

this loop and next statement will be

executed that is k is equal to k plus 2

now k plus 2 that means k value of phi

phi plus 2 now

k value will be 7 next it will execute

this print statement so control goes to

here okay now control goes to the main

followed and here ranges from 1 to num

plus 1 there is 1 2 3 so it will come

out of this loop and it will end the

execution so we got the output .

Like this it will continue the execution and it will print this Pattern.

ok that's it for now thank you for watching don't forget to subscribe my channel I'll meet you next class till then take care .


Video tutorial to this program



Program :

num = int(input("enter the number of rows :"))

k=1

for i in range(1,num+1):

 for j in range(1,k+1):

  print("*",end=" ")

 k=k+2

 print()


Output :

enter the number of rows :5

*

* * *

* * * * *

* * * * * * *

* * * * * * * * *


[Program finished]


For more program 

click here











Post a Comment

0 Comments