01 - PATTERN PROGRAMS IN PYTHON PROGRAMMING

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello friends welcome back to our channel so in today's session we'll see a pattern programs so for the following patterns so first pattern so this is a pattern we need to print so in order to print this pattern so how to write the logic see first of all coming to the pattern programs the data whatever the data we are representing either is star or alphabets or numbers anything so that is represented in terms of rows and columns so the outer loop so we have to write the two different loops okay two loops so two loops should be written the outer loop the outer loop represents the rows the outer loop represents the rows and inner loop inner loop represents the columns and also in the inner loop we have to write the print statement that means output statement okay so first we'll write the outer rule first we have we'll write the outer loop that means how many lines are there five lines we need to print five lines so in python for i in range of let us take 6 okay or simply we can say we can take um okay so if you take this file this implies the values of i will be from 0 1 2 3 and 4 okay total five five rows five rows and for every row for every row we need to print the value okay we need to print the value so inner loop this is the column okay inner loop this is a column for j in range see if you give here how many members we have to do so it is a first if it is one zeroth row if it is zeroth row one star should be printed so i have to add plus one and in the first row so let us take this is 0 this is 1 this is 2 this is 3 and this is 4 so in the 0th row 1 star 1 so one time this print statement should be repeated so what i have to do either is 0 so i can simply write i plus 1 simply i can write i plus 1 column and here we need to print star star symbol okay so we have we know that every printf or every print statement in python will print the data in new line but here what should be done so the line the star should be printed in a same line in the same line so in order to print the star in the same line so what we have to do we have to use a end operator i mean end parameter so end is equal to this one so you can see if it is 0 if it is 0 i plus 1 so this will iterate from j value iterates from 1 to 3 4 and 5. so whenever i becomes 0 j value becomes 1 ok range 1 range 1 means it will iterate one time okay and if it is one if it is one range of two range of two means zero and one two times it will print two times so you can observe here star is printed two times and if whenever i becomes two range of three here three becomes three means zero one two that means three iterations three times the print statement will be executed and star will be printed three times you can see three times it should be printed right and you you can observe here after every iteration so after completion of this inner loop okay after completion of the inner loops the next iterations should start with the next line otherwise the same thing will be printed in a single line so after every iteration after every row after completion of every row the new pattern should be printed in a new line so for that purpose after completion of the inner loop we need to use some empty print so that whatever the statement we are getting so for you can observe here if it i is equal to zero range of one range of one means one time it will be printed star will be printed after star we are just using the print that means automatically it will comes on the second line right next i becomes one i becomes one means now it will be two it will be two means two times it will be repeated zero and one so 0 1 1 star and star here star will be printed your star will be printed because we are using some end operator and again print again it will move with the third statement third line and again fourth line again it will be printing on fifth place that means i is equal to four whenever i becomes five automatically this will the loop will be ended so we will get the pattern in this way right so this is the simple logic for printing the pattern so if you want to take the value from the keyboard so just use the input function so n is equal to int of input so that if you take some 10 and pass n here if you take some 10 so 10 lines 10 lines the pattern will be printed okay 10 lines the pattern will be printed so i will show you the code by executing on the interpreter right next the next pattern we'll see two patterns now so just by modifying a small logic we can take the next one so next one is i think yeah here we do that reverse pattern just now we have seen one pattern so the reverse of that pattern will see now so how to print this pattern so you can see the same logic the same logic so here it is 0 it is 1 it is 2 it is 3 it's a 4. now what we have to do for the 0 5 times it should be printed so rather than taking from 0 to 4 so here in such case we can take in a reverse order that means a decremented way so you can see let it be 5 4 3 2 1 so these are the row numbers row numbers so 5 4 3 2 1 for this purpose what we have to do so take the range function inside the range function decrement the values so go with five start with five so i will be five in the first iteration and i so with the minus one okay with minus one after first iteration five will become four after second iteration four will become three three will become two two will become one so it should start at one so it should iterate from five to zero with a minus one five to zero with a minus 1 right and here instead of taking all these things here also same thing so if i is equal to 5 j should repeat 5 times so 5 times the star will be printed right so 5 times we have to print the star so j should iterate five times so use the same thing i i comma and here also zero comma minus one so if i is equal to 5 so you can see here the values will be 5 4 3 2 and 1 and here also so if i is equal to 5 j will be 5 that means 5 times the star will be printed so here it is and whenever i becomes four for i j in range of four comma zero minus one that means four three two one okay so this is the logic so four five four 3 2 1 okay and here it will be 4 3 2 1 here it will be 3 2 1 here it will be 2 1 here it will be 1 right so like this we can simply use the negative uh decrement decrement operator that means decrementing the value in the range function which will give the result in the pattern in this way simply there is no other modification we can do so instead of 5 here we can take it as a n n 0 and the same thing okay here also it will be going with 5 four three two and one so simply the star will be printed and the same logic so if we are giving some end operator because all the stars should be printed in the same column right after after each and every column it should come with the next iteration right so this is a small and very simple patterns and further we'll go with the other patterns so meanwhile i will execute the same logic the three lines or four lines of code in the system and i will show you the patterns so let's move on to the system hi friends so just now we have seen uh two patterns in python programming so we will see the logic for that one so i will execute this one so take the n value read the n value so that we can iterate the number of rows so we can enter number of rows to be displayed so here we can take the value of n and we can iterate them so outer loop is for rows so for i in a range of uh let us take some n right and our inner loop is for columns for j in the range of i plus one right and print the star okay print the start i will show you what is the use of end here so i am just executing so you can see if i give 5 see there is no pattern so all the stars have been printed in the next line because print will always print the star in in the same way if you go with the end operator i mean the end parameter so the next output will be printed in the previous present output so you can see if i execute this one again all the stars have been printed in the same line now we have to differentiate from one row to another row so after completion of each and every row then next the star should be printed in the next row so for that i am giving the empty print so you can see if i go with the file so we'll have whenever i becomes 0 1 will be printed right so 1 star will be printed and whenever i becomes one two stars will be greeted so because the line number will be zero one two three four right and see if you go with the ten automatically the pattern will be i mean the number of lines will be some 10 lines so like this we can implement the pattern right this pattern and once again the reverse order what about the reverse order so for that we have changed the logic with the negative decrement so start with the n and go with the end with 0 and with a minus 1 decrement with minus 1 for every iteration so here also you can go with the i comma 0 comma minus 1 and simply you can execute so that will get the pattern in a reverse order because if it is n the n times the star will be printed because i ranges with the en to 0 so i will be having from n when i becomes n j will be also having n so n times the star will be printed in the next next iteration n minus 1 n minus 1 times the star will be treated if you go with the 5 so first iteration 5 5 stars will be printed in the next iteration i i becomes 4 so 4 stars will be printed so how many i value what is the i value the same number of times the star should be printed here right for that purpose the same thing we have applied for inner loop and outer loop so that we'll get the reverse pattern right so hope you understood this one if you are having any doubts regarding these patterns so feel free to post your doubts in the comment section definitely i will try to clarify all your dogs and if you really enjoyed my session like my session share my session with your friends and don't forget to subscribe to our channel thanks for watching thank you very much
Info
Channel: Sundeep Saradhi Kanthety
Views: 42,070
Rating: undefined out of 5
Keywords: SUNDEEP, SARADHI, KANTHETY, PYTHON, PROGRAMMING, FEATURES, APPLICATIONS, INTERPRETER, PYTHON SHELL, INTRODUCTION, BEGINNERS, PLATFORM INDEPENDENT, PYTHON BASICS, PYTHON FUNDAMENTALS, LIST, SET, TUPLES, DICTIONARY, FUNCTIONS, LIBRARIES, PYTHON IN TELUGU, TELUGU TUTORIAL, PYTHON FIR BEGINNERS, indentation, control structures, operators, membership, loops, applications, variables, identifiers, recursion, types of arguments, complete python, pattern programs, nested for loops, patterns, triangular patterns
Id: IhnEBQF6AGs
Channel Id: undefined
Length: 14min 30sec (870 seconds)
Published: Wed Aug 11 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.