Python Loops Tutorial | Python For Loop | While Loop Python | Python Training | Edureka

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone this is surah from ad Rekha and in today's session we'll be focusing on various loops that are available in Python so without any further ado let us move forward and have a look at the agenda for today so first we'll see why to use loops what are the reason of introducing loops in the programming world let me see what exactly are loops and then we'll focus on various types of loops that are there in python namely while for a nested i'll be explaining you all these three loops with examples after that I'll give you a brief summary of all the things that we have discussed in today's session so I hope we all are clear with the agenda kindly give me a quick confirmation by writing down in the chat box so that I can move forward all right today says move forward so does Natalie Siddharth Siam Java titania Kanaka all right fine guys so I've got confirmation from almost everyone so let us move forward and see why we need loops now let us understand this with an example that is there in front of your screen suppose you are a software developer and you are required to create a software module for payroll processing of all the employees in your office now one of the things you need you need the salary of those employees the bonus and the total amount that they'll get at the end of the month right so all these things for each employee you need to print so for each of the employees you need to print all these three details now there are two ways of executing this task so let us see one of those two ways so the one way is you can actually write a logic to calculate the total salary of each of the employees that includes all the fields like salary bonus in total and you are going to write that logic for all the employees that are there in your office there might be hundreds of employees that are there in your office so you need to write the closet or you need to write the code for all of those employees so this process is actually pretty hectic you need to repeat the same logic for total amount of employees are there in the office I am just giving you an example of three employees but what if you're have like hundreds of employees so at that time this particular process will not work this will not only increase the size of the code it will make it more complex and less efficient now another way of approaching this task would be you write this logic to calculate the Sal you keep on hydrating that logic for the total number of employees that are there so when this Lube runs once it'll print the side of your first employee when the loop runs for the second time it will print the salary of the second employee similarly it will keep on repeating so if you have a hundred employees it will repeat four hundred times now what advantage we get here the major advantage that we get here is we don't need to write the logic for each employee in order to calculate the salary we can write one logic and keep on repeating it for all the employees so this way the size of the code gets reduced the length of the code is reduced at the same time it reduces the complexity makes it more efficient and even increases the speed of execution so this is just one example in order to show you why we need loops so there are hundreds of thousands of examples that you can think of why we need loops right so this is just one simple example that I've shown you in order to make you understand why we need loops so if you have any doubts any queries please write it down in your chat box Dave says he's clear our soda siddhart Siam Kanaka nationally jothee or red wine so I've got a confirmation from almost everyone so let us move forward and see what exactly our loops let me explain you this with the help of the flow chart that is there in front of your screen now what our loops loops basically allows us to execute a statement or a group of statement multiple times let me explain you this with the help of an example that is present in front of your screen now over here what happens the control comes here and checks the condition so if this condition is true it will go on and execute the conditional code that is here this is nothing but the statements that are present inside the loop so it will execute that and again it will go back and check the condition so if the condition is still true then again it will execute the conditional code of the statements present inside the loop and it will keep on repeating until this condition becomes sports and the moment this condition becomes false the control will move out the loop and it'll execute the statements that are present after that loop now one thing to notice here guys is that there can be two kinds of loops one is finite this is actually the flowchart for the finite loops and another can be infinite now in infinite loops what happened the candy we'll never be false so at that time the control will never come out of the loop so it will keep on repeating and it will never stop that is what infinite loops are so basically the condition will never be false and through that the loop will be executed infinite number of times now there is one more way in order to categorize loops that is called post-test and pretest in postage loops what happened the control will first enter the loop and then in the end it will actually check the condition but in pretest loops the control will enter the loop only when the condition is true so the condition is checked in the beginning of the loop in pretest loops but in post-test loop the condition is checked at the end of the loop now in python there are no post-test loops present there are only pretest loops so we'll focus on pretest loops in today's session so I hope you all are clear with what exactly our loops if you have any doubts any questions you can write it down in your chat box I'll be happy to help you alright the day says no questions so does Siam Dorothy Kanaka alright so I've got a confirmation from everyone so we'll move forward and we'll see various type of loops that are present in Python so Python basically supports three kinds of loops one is vy4 and nested we'll look at all these loops one by one and I'll explain you with examples as well so first we'll have a look at while loop so while loop is basically used when you don't know how many iterations are required so let me explain you this with the help of the flowchart that is there in front of your screen now over here what happens the control will move inside the loop only when this wild condition is true and when it is true it will execute the body of the loop and then again it will go back and see whether the condition is still true or not if it is still true then again it'll execute the body of the loop and it will keep on doing that until the condition becomes false and the moment the condition becomes false it will come out of the loop and execute the statements that are present after the loop now this is syntax for while loop firstly to write while then you write the expression of the condition then you give a colon and the statements or the body of the loop now why we use while loop basically I told you earlier as well loop is used when you don't know how many iterations are required so you don't know how many times you need to execute the statements that are present inside your loop so that is the reason why we use while loops now let me show you that with the help of an example I'll open my PI charm and I'll give you a very basic example of using while loop and after that I'm going to increase the complexity of the code so first we'll see a very small introductory example of a loop in which I'm going to print the integer values between 0 to 9 that won't include 9 so it will print 0 1 2 3 till 9 but it burned in huge 9 so let me open my pie thumb and show you how to do that now this is my pie charm guys so over here as I have told you earlier as well I'm going to print the integer values between 0 to 9 but that won't include 9 so for that what I need to do is I need to first define a variable let me name it as count and I'm going to initialize value to it that is 0 now after that I'm going to use a while loop and I'll write while and then I'm going to give a condition which says that when count becomes greater than 9 it should come out of the loop alright so now what I'm going to do is I'm going to just type in friend let it be number colon comma print count right now I'm going to increment the value of count count equal to count plus 1 yep now when I come out of the loop I want to friend say goodbye yeah looks fine now let me tell you what I've done here I've defined a variable and I've initialized the value 0 to it after that I have used a while loop in which I've given a condition that says that count should always be less than 9 because I want to print values between 0 till lines this won't include time let me tell you that so my condition says that the loop should be executed only when the count value is less than 9 the moment it becomes greater than 9 then the control should come out of the loop after that it's just a sent general syntax I have given a colon and then I have written a print statement that will print the count value and after that I have increased the value of my count by 1 and finally when the control comes out of the loop I want to print good part so let us see whether it works or not I'm going to run it and as you can see that it works so we are 0 1 2 3 4 5 6 7 & 8 and finally when the control went out of the loop it has printed goodbye this is just a very small example guys now let me go back to my slides now the example that we just saw was a very simple example so I'll increase the complexity of it and I'll give you one more example so let us move forward with that so over here what I'm trying to do is I'm trying to code a little guessing game all right so what happens in this guessing game so there will be a random number that should be generated between save 0 to 20 and you need to guess that number so the number that you have guessed is less than that random number then it will print number is too small if you have guessed the number that is greater than the random number then it will print that number is too large and the moment you get the right answer you'll exit the while loop and you have won the game basically so it's just a pretty simple example but this is a perfect example in order to show you why we use while loop because if you notice here I don't know how many iterations are required in order to guess the correct answer so at that time while loop is a perfect solution to this problem so without wasting any time I'll actually open my pie charm and show you how to execute this so this is the code here guys let me explain you each and every line that is present here now what happens first I need to import a module that is called random in order to generate a random number now over here I have defined a variable N and I've given a value to it that is 20 because I won the random number that is to be generated should be between the range 0 to 20 now I have taken one more variable and I've named thus to be guessed and over here it should be an integer types of written end and this logic will generate the random number that I am talking about and this will be generated between the range 0 to 20 so how it will be generated it will be generated with the help of random modules that we have imported so it will be n random dot random plus 1 this will actually generate a random number between 0 to 20 any doubt still here guys all right so no doubt still here so after that what happens I have defined one more variable guess and I have assigned a value to it or initialize the value to it 0 all right so now comes the while loop now in val loop i have given a condition which says that the number that i have guessed if it is not equal to the random number then enter the loop now once you enter the loop you need to input the new number the number that you want to get again now if that guessed number or the number that you are guessing is greater than 0 then again there will be one more s condition which says that the number that you have guessed is greater than the number that has been generated or the random number that has been generated then print number is too large and if the number that you have guessed is actually smaller than the random number generated then print number is too small now there is one more condition that is else which means that when the number that you have guessed is less than or equal to 0 then that means you are giving up so it will break it will come out of the loop and it will print sorry that you are giving up that's when your game gets over and you have lost it finally if you have guessed the correct number then it will print congratulations you have made it so I hope you have understood the code that I was explaining here any doubts any queries you can write it down in your chat box it's a very easy example but a very perfect example in order to show you how while loop works because over here I don't know how many iterations are required in order to guess the random number that has been generated all right so we have no questions so let us go ahead and execute this and see what happens all right so it asks me for a new number so it has to be between 0 to 20 so yep I'll type 10 and let's see what happens so it says number is too small that means it is between 10 to 20 how about 13 all right so I've guessed the correct number and it says congratulations you have made it now over here as you can see that it took only two iterations for me in order to get the correct number but what if it would have taken more iterations I mean I'm pretty unclear how many iterations it will take for me so that is the reason why we use while loop because we don't know how many iterations are required now we can run this program again and I can show it to you once more ask a new number so I'll just type in say 14 it says number is too large so I'll type in 11 again the number is too large that means it is between 0 to 11 so how about 8 guys number is too small so now now as you can see that already three iterations have occurred and for the fourth iteration definitely the random number will be somewhere between 8 and 11 so how about 10 so congratulations you have made it and the control came out of the while loop and it has printed congratulations you made it so any doubts till here guys all right so we have no doubts I've got confirmation from almost everyone so we'll move forward and see for loops in Python so for loop is basically used when you know the number of iterations that are required unlike while loop where you are not sure about the number of iterations that are required in for loop you know how many times the statement that are present inside the loops need to be executed the for loop provides you with a syntax that will include 3 fields basically or you can say 3 informations so first will be the boolean condition then comes the initial value of the counting variable and then the incrementation of the counting variables so as you can see from the syntaxes well first you write for name of the variable in the range then you specify the range in which that variable should be or and then you specify the range that means from which point at which point it should be executed so you know the number of iterations required then only you use for loop now over here as you can see from the flow diagram itself the control comes to this and it will see the item from the sequence it will execute the statement go back again and then from the range it will pick up the next item again it'll execute the statement again go back and then from the range it will pick up the third item and it will keep on executing until the range becomes over or that is the last item from the sequence so when there are no items in the sequence it will go on and execute the statements that are present after the for loop so this is how for loop works guys now let me just give you a very small example of how for loop works I'll open my pie charm again and I'll start with a very small example and then I am going to increase the complexity of our code like I have done that in while loop now over here what I'm going to do is I'm going to first define a list and I'm going to name it as fruits so what all fruits you like guys I'll first type in mango then I like grapes and finally I'm going to write and say Apple yep so this is my list which contains the three fruits mango grapes and Apple now I'm going to define a for loop and over here what I write I'll define a variable say fruit for fruit n fruits give a colon print current fruit and type in fruit now when you come out of the loop just print again goodbye so I have declared a list and the name of that list is fruits now that fruits list contains elements which are mango grapes and Apple now after that I have defined a for loop which says that for a variable named fruit in fruits so this will give me the range fruits will give me the range as you know that in the fruits list there are only 3 fruits so I know it will I trade only thrice first for mango then for grades then for Apple so this is the difference between the viral for loop in for loop I know that will take only 3 i trations after that print the current fruit that's all and when the control moves out of the loop print goodbye it's pretty easy guys so go on execute this and see what happens so yep the current fruit first is mango then comes grapes there comes apple and then finally print goodbye so any doubt seller guys you can ask me if you have any questions any queries please write it down in the chat box they says no questions sort of Zarate Siam Natalie alright everyone's clear nice to hear that so what I'm going to do is I'm going to increase the complexity now as I've done that in while loop as well so I'll show you an example first let me go back to my slide so what I'm going to do in this example I'm going to calculate the factorial now one thing to notice here guys again in factorial also I know how many iterations are required because if you see if I'm calculating the factorial of 5 and I know that I need multiplication five times first I need to multiply as five with pause and four with 3 and 3 with 2 and then 2 with 1 so this way I require only 4 I trations so I know the number of iterations required so it's a very good example in order to show you where we should use while loop and where we should use for loop so let me go back to my pycharm and execute this practically so this is the code in order to find the factorial of a number so over here what happens first I need to input the numbers that I want to calculate the factorial of after that I have defined a variable factorial and I've initialized the value to it which is 1 now I have defined a condition if the number that I have entered is less than 0 then print the number must be positive because I can't calculate the factorial for negative numbers right and again I have given one more condition which says that if number is equal to equal to 0 then factorial is equal to 1 and then else condition says that when number is greater than 0 then I've used a for loop which says that for I have defined a variable I in the range 1 to num plus 1 when I write num plus 1 the range will be between 1 to num plus 1 but it won't include num plus 1 so it will only be including one till num all right so after that what I have written factorial is equal to factorial into I so factorial was 1 earlier then it will multiply by I I will also be 1 in the beginning and then again it will go back and it will become 2 similarly it will keep on increasing until it becomes numb so till that time it will keep on executing the loop and the moment it becomes equal to num it will come out of the loop and it will print the factorial value so do you want me to repeat it once more or are you all clear with the code that I've written here all right so they want me to repeat the code once more all right Dave so what's the first line says here first line says input an integer number so that number whose part really want to calculate basically so you enter that number after that I have defined a variable factorial and I've initialized the value to it which is 1 then I have given a condition which says that if the number that I have entered is less than 0 then print that number must be positive obviously I won't be printing the factorial of a negative value then I have one more condition Elif which says that the number that are given if it is equal to 0 then definitely the factorial is equal to 1 now one more else condition which says that when the number is greater than 0 at that time execute the for loop which says that when I is in the range 1 to num plus 1 now notice here the range is between 1 to num plus 1 but it won't include num plus 1 it will stop till num itself all right so after that what I have written I have written factorial is equals to factorial into I now let me take an example since the factorial value is 1 here so this will be equal to 1 and then 1 into I I will be 1 in the beginning so 1 into 1 is 1 of that it will again go back and it will become 2 so factorial is 1 earlier 2 1 equal to 1 into 2 is 2 now the factorial value will be updated it will become 2 then again I will go back it will become 3 so what do you have factorial is equals to factorial value is 2 earlier so will become 2 into 3 similarly it will keep on repeating until I reaches num value so once the factorial is multiplied with the value num this will print factorial and come out of the loop so I hope you have no doubt still here if you have any doubts you can write it down in your charge box I'll be happy to help you any doubts guys alright so there are no doubts so let me go ahead and execute this and show you if it works or not so I need to enter the number so let's say I want to calculate the factorial of 3 which is 6 so if I want to enter one more number so what I can do is I can start it once more so 1l type I can type again 4 so it prints 24 which is absolutely correct so now still here guys you can ask me all right no doubt so we'll move forward and we'll see what our nested loops in Python so python basically allows us to use a loop inside and another loop for example you can use a for loop inside a for loop or you can use a while loop inside of a loop and at the same time you can use a while loop inside a for loop as well and a for loop inside a while loop as well so that is basically what is called at nested loops now we'll have a look at the example of nested loops as well don't worry so let us move forward and see one example of nested loops now over here what I'm going to do is I am going to write a code in order to simulate a bank ATM alright so for that I'm going to use nested while loop and what will happen first you need to enter the four-digit pin and then you can perform the following functions you can check the balance you can make a withdrawal you can deposit some money and you can even if you don't want to do anything you can tell the machine to return your car as well so let me show you how it is done I'll open my PI charm once more so this is the code that I've written in order to simulate a bank ATM and explain you each and every line so don't worry about that so first line is nothing but a print statement that says welcome to iron bank of Braavos atm alright and then I have defined a variable restart and I've assigned a value to it that is why similarly chances of a sign of value that is 3 and this is the balance that I'm going to initialize that is 67.1 phone notice you over here you won't get more than 3 chances in order to write the correct password now comes the while loop which says that when chances are greater than or equal to 0 at that time what we'll do you need to enter the pin so you need to input the four-digit pin that you have and if that pin is 1 2 3 4 then it will print that you have entered the correct pin now comes one more while loop which says that while restart should not be in this particular tuple that is the value of restart should not be n capital n or small n o or capital n so it should not live within this particular sequence that is n capital n oh no and n but we know that the restart value is y so it will enter the while loop now over here what will happen it will give you four options first option is in order to check your balance for that you need to press one to make a bit roll you need to press two in order to pay in some cash or you need to deposit something you need to press three or you want your card box you need to press four so these are the four options that will be given to you so when you choose option one it will print the account balance so over here as you can see that your account balance is and the balance that is there in your account after that it'll ask you for restart so you need to input that value so that will say would you like to go back and if you restart value lies in this particular topple then it will break and we'll print a thank you statement but if you want to continue or you want to go back then you can press anything else apart from small n n o or this no or capital n so if you press any other button apart from these it will actually go back and in the while statement as you can see it says that it is not present here so it will give you all these four options once more so I hope I am cleared in here if you have any doubts till here you can ask me any doubts case alright so it is clear now after that what if you choose the another option in which you need to make a withdrawal so for that what will happen you need to enter the amount that you would right to withdraw which can be a float number it cannot be an integer number so that's why I've used float here so you need to enter that value and once you enter that value it will check whether it is in this particular list or not that is 10 20 40 60 80 100 now by default it will give or restart why because you need to enter the amount 1 smooth so again it will go back and it will give you all four options so you can choose a Twitter all option again and you can choose a number which is present in this particular list now when you choose withdrawal equal to equal to 1 at that time it will again ask you please enter the desired amount so this is for option 2 now when we talk about option 3 it is pretty much similar to the couple of options that we have discussed before so it is pretty much similar to that over here again whatever the amount is that you want to pay in the how much firm amount that you would like to pay and plus the amount that you are depositing so it will print the balance that will be equal to balance plus the amount that you are depositing again it last you for restart if you press anything apart from this particular tuple then it will go back to the while statement and it will give you all these four options similarly for auction for as well now what happens when you enter the incorrect pin so there is one more condition in the end which says that if the pin that you have entered is not equal to one two three four then it will print that incorrect password and it will decrease the chances by one so earlier you had three chances if you press the incorrect pin once it will decrease your chance and it will make it as two again if you write the incorrect password then again it will make it as chance it equals two chances minus one which will become one and if the third time also you do the same thing then the chances would it comes you and the moment it becomes zero then it will print no more tries break and come out the loop that's all guys so any doubt still here guys you can ask me all right so we have no doubt so let us go ahead and execute this and see what happens so please enter your four digit PIN so I will just write one two three four and give me four options which is one for balance two for withdrawal three for pain for the return a card so if I want to check my balance and put in 1 so it has printed my balance is 260 over seven point one four and then the restart value that I was talking about it is asking for that let me just make it big for you here would you like to go back so if I press n here it is come out of the loop and it'll break and if I press anything apart from small n capital n Oh small N or capital n it will actually go back and ask gave me all the four options out with it so if I press Y will again give me all the four options or other you can see that press one so again if I want to make a withdrawal I'll press 2 how much amount that I would like to withdraw say I want to withdraw ten so my balance has reduced from sixty seven point one four two fifty seven point one four so would you like to go back so I will again press Y and it will give me all four options if I want to pay in something that is I want to deposit something and press three how much about that I would like to deposit and say ten so my balance became again sixty seven one for again it is asking me really like to go back no I don't want to go back so I can type in n so yep so it says thank you and again ask me me for four-digit pin so let me show you what happens if I die the incorrect pin say if I write one one one incorrect pin if I write that then again again incorrect again incorrect so we have no more tries it has come out since I've exceeded the chances that I was given so I was given three chances I couldn't write the correct pin in those three chances so as you come out of the loop and it will stop so this is an example of nested vine now let me go back to my presentation and I'll show your example of for loop as well so this is an example of nested for loop so over here what I'm going to do is I'm going to write a code in order to print the Pythagorean number between a particular range so what happens is suppose if I want to enter the number 20 that means I want the Pythagorean numbers between 1 to 20 so particular numbers are nothing but the integers which satisfy a square plus B square is equal to C squared so at that time it will print all the Pythagorean numbers that are possible between 1 to 20 3 4 5 you can see that 3 square 4 square is equals to 5 squared 9 plus 16 is equals to 25 similarly it goes 4 5 2013 6 8 10 8 1579 12 15 similarly for 12 16 and 20 Dover you guys I'll go back to my Python and I'll explain you how you can do that so this is the example of a nested 4 so first over here I need to import certain modules in order to use the square root function so from math module I am going to import the square root function after that last me for the number in the example if you can remember the slides where I've written 20 so does printed the particular numbers between 1 to 20 that same number it will ask me and it will print the Python numbers between 1 to n so whatever the number n that I am going to put in or give an input after that I'll run a for loop and it will say that for a which is a variable in range 1 to n plus 1 that means 1 to n that means 1 to N plus 1 but don't include n plus 1 after that there is one more variable B which is in the range a comma n that will not include n it'll only include till n minus 1 so the square root C square I've defined one more variable C square is equal to a exponential or a ^ 2 similarly B raised to the power of 2 alright and then what I'm going to do is I'm going to calculate the square root and then what I'm going to do is I'm going to define one more variable C and it will be an integer that will be the square root of C square so if that C square is minus C square is equal to equal to zero then print ABC it's pretty simple logic guys okay explain it once more name so this is an example of nested four so over here what I'm going to do is I'm going to first import the square root function from the math module I up to that I'm going to input a number so if you can remember in the slides I have given it as 20 so it will print the Pythagorean numbers between 1 to 20 over here also it will print the Pythagorean numbers between 1 to n so whatever the value of n you input that will be depending upon it so the particular numbers will be depending upon the values that you input so it'll be printing the particular numbers present between 1 to n after that I will run a for loop which says that for a should be in the range 1 to n plus 1 that will not include n plus 1 guys it'll only include n so 1 till n plus 1 but don't include n plus 1 after I've defined one more for loop which says that for be in range a comma n it won't include n it will be 10 only n minus 1 I have defined one more variable here which is equal to C underscore square that is equal to a square plus B square now after that I've defined one more variable C and this will be actually the integer of the square root of the C underscore square all right so whatever value that you will get here the square root of that value will be converted to an integer value and will be assigned to C now one if condition I will be using here which says that if C underscore square minus C square is equal to equal to zero then print ABC that means that will be a pie too good a number so this is a pretty simple logic guys if you have understood it just give me a thumbs up or you can ask me any questions that you have in your mind all right so I hope you have understood the code that have explained you here now let us go ahead and execute this and see what happens yeah so the first number that I'm going to type in say five and give me all the particular numbers present between one to five so we have only one particular number that is three four five in that range now I'll execute this once more and I'll type in ten here so we have two particular numbers there are three four five and six eight ten similarly if I execute it once more and I type in a big number say 25 yeah so we have these many pythagoras numbers present wien 1 225 so I hope you have understood how to use nested for loop if you have any doubts please write it down in your chat box so we have no doubt Davis clear solar siddhart gnarly jority Siam kanika Thani everyone's fine so I've got a confirmation from almost everyone so we'll again go back to our slides and we'll have a look at one more example now in this example I'll actually be using a for loop inside a while loop so what is this example I want the bulk reservation of train tickets so I have like group of people who are travelling somewhere and I want to give their details such as name age and sex I want that to happen in bulk I don't want to give it one by one I just want it to happen in bulk so for that what I'm going to use is I'm going to use a for loop inside a while loop as I told you earlier as well you can even use a while loop inside a for loop but for now I'll use a for loop inside a while loop and see what happens so let me go back to my PI charm so this is the code in which I will be using a for loop inside a while loop so first I have defined a variable traveling so in which you need to input whether yes or no so if you're traveling you say yes obviously and then we'll have a while loop which says that while the condition is traveling equal to equal to yes that means if you are willing to travel enter the number of people who are traveling so you need to enter the number of passengers that are traveling and that will be assigned to a variable num now there'll be a for loop which says that for num in range 1 to num plus 1 but it won't include num plus 1 enter the name enter age and finally whether the person is male or a female and then print all those values now one more thing here is again it will ask you whether you have missed someone or not so you need to input that oops forgot someone so at that time you can write in yes if you have forgotten someone that again it'll execute the loop again it'll ask you the number of people traveling in all these details if you write in anything apart from yes that means you have not forgotten anyone and it will come out of the loop so it is a very small example but a very good example to understand how for loop can be used inside a while loop so let me go ahead and execute this whether you're traveling I would say yes I am traveling number of people traveling I would say 3 name is Sora ages 78 male alright so again it has asked me for one more name so I'll say need is 90 you know female male yep so one more name I need to type in say I would type in geography is 98 made of females female and yup it will print all those details for me so now it is asking have you forgotten someone so if I type in and say yes then it'll again ask me the number of people traveling that means it is again executing the while loop so if I would say the number of people traveling is 1 and I would type in the name of the person that was traveling so I would just say Siddharth whose is is 77 and he's a male yeah again it has asked me so if I type in anything apart from yes say if I type N so yep it'll come out of the loop and this is how you can actually use a for loop inside a while loop so if you have any doubts you can ask me guys alright so we have no doubts as natalie says no doubts Siddharth Dorothy everyone I've got a confirmation from almost everyone so let me just open my slide and yep so this was an example of a for loop inside of while loop now I am giving you an assignment guys what you have to do you have to come up with a good problem statement in which you need a vile OOP inside a for loop and you need to get that assignment before the next class so let us move forward and I'll give you a brief summary of what all things we have discussed the till now first we saw why we need loops we actually use the example of software module for payroll processing in which I showed you two methods the one is manual and the another one in which you are using loops after I told you what exactly I loops and we saw various types of loops in Python namely vile foreign nested then we focus on each of these loops we started with while loop and I explained you well to use by loop I gave you two examples of I loop similarly for for loop I explained what exactly's for loop how it works its syntax and two examples again for for loop when you talk about nested loops again I've explained you the syntax how to use it and I've given you three examples for nested loop as well as I showed you earlier in that your assignment your assignment is to write a code in which you are using a while loop inside a for loop alright so just bring it in the next class this video will be uploaded into your LMS so you can go through it if you have any doubts any questions you can bring it in the next class or you can ask our 24/7 support team as well thank you and have a great day I hope you enjoyed listening to this video please be kind enough to like it and you can comment any of your doubts and queries and we will reply to them at the earliest to look out for more videos in our playlist and subscribe to our Eddie Rica channel to learn more happy learning
Info
Channel: edureka!
Views: 190,870
Rating: 4.8625231 out of 5
Keywords: yt:cc=on, python loops tutorial, python for loop, while loop python, python loop, python loops, python loops explained, python loop syntax, python loop example, python tutorial, python training, python programming, python programming language, python certification, python classes, python edureka, edureka
Id: zFvoXxeoosI
Channel Id: undefined
Length: 40min 18sec (2418 seconds)
Published: Wed Mar 29 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.