There are complex triangle patterns at basic level of programming. Since in this Part we learn how to print given different types of star patterns.
Problem1:- Print Given Pattern in Python using for loop.
A
A B
A B C
A B C D
A B C D E
CODE FOR PROBLEM 1:
EXPLAINATION:-
As first line of code that it runs for 5 times where i initialises to 1 and run upto where i less than 6 condition satisfies. (i<6,where i=1,i=i+1) since in every time where condition satisfies the code present in given for loop executes .
since values of i is 1,2,3,4,5 for whole for loop then consider that it acts as 5 rows in output.
Hence in next for loop we initialises k to 65 which ASCII code for alphabet A , hence as i increases the value in second for loop range is increases since range in second for loop acts as column in output .
Hence it considered as 5×5 matrix
where for,
i=1 : k=65,
i=2 :k=65 ,66
i=3:k=65,66,67
i=4:k=65,66,67,68
i=5:k=65,66,67,68,69
Hence for first for loop satisfies then second for loop prints the ASCII value for given code .
ASCII code and its value are given in PDF below.
Download
As first line of code that it runs for 5 times where i initialises to 1 and run upto where i less than 6 condition satisfies. (i<6,where i=1,i=i+1) since in every time where condition satisfies the code present in given for loop executes .
since values of i is 1,2,3,4,5 for whole for loop then consider that it acts as 5 rows in output.
Hence in next for loop we initialises k to 65 which ASCII code for alphabet A , hence as i increases the value in second for loop range is increases since range in second for loop acts as column in output .
Hence it considered as 5×5 matrix
where for,
i=1 : k=65,
i=2 :k=65 ,66
i=3:k=65,66,67
i=4:k=65,66,67,68
i=5:k=65,66,67,68,69
Hence for first for loop satisfies then second for loop prints the ASCII value for given code .
ASCII code and its value are given in PDF below.
Download
Some Same types of examples given below for practise .try to examine its working by own or comment me I give you whole explanation about that code and its output.
Problem 2:- Print Given Pattern in Python using for loop.
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
CODE FOR PROBLEM 2:
Problem 3:- Print Given Pattern in Python using for loop.
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
CODE FOR PROBLEM 3:
Problem 4:- Print Given Pattern in Python using for loop.
*
* *
* * *
* * * *
* * * * *
* * * * * *
CODE FOR PROBLEM 4:
Problem 5:- Print Given Pattern in Python using for loop.
0
1 2
3 4 5
5 6 7 8
CODE FOR PROBLEM 5:
Thanks to visit My Page.
- Comment me for any doubt comes in your mind.
