Welcome to the Python program so today we'll be starting with the while loop now I'm now going to give you a scenario when we will be using the while loop. Now assume that you are a doctor and you have your own clinic. Now you must treat your patient and assume that you are a popular doctor. So there are a lot of patient and what you can do is you can give them a token number that is your receptionist, give them with the token number. So you start with 12345 and you go on and you treat your patient one after another. So how can you write a program for this which will just change the token number you press whenever you whenever you need a new patient, it will come up and a new token number will be displayed.
So you need to set up a program for this Okay, so you put a monitor outside your clinic through which in the reception area where the people can see which Number is being called right now and that concern person should come inside now, let us see how we can achieve this using a while loop. So, first time right why c equal to equal to one then give a colon Press Enter right friend token number give a comma right and again give a comma open coats and write me Please come in okay now, this will be user defined. So, here I have to use an input statement So, C is equal to input continue then carry on Write zero or one. So, this whole thing will be inside inverted commas. Now, first here I have defined n and here I have defined c. So, in the beginning I have to mention what n will be invert c will be.
So, first I'll define n is equal to one and C will also be equal to one, because this is the first patient. So C should be one because you're starting. So, whenever you run this code, what will happen now, let me do one thing, let me just change this seat to integer because here one or anything that I input will be inputted as string. So I converted to integer Now, whenever I run this code, what will happen? So token number one make that Please come in. So the first thing will be this because n is equal to one here and whenever I execute the code, this n will take up the value one Then this will sentence will be printed and now it will ask for the next one.
So, token number one the papers patient will go in and we will treat the patient and whenever he or she will come out of the trading from your cell your reading from you then you have to give an input to call the next patient. So, if you press one what will happen and if you press zero what will happen So, whenever you will press one this program will enter the while loop because here I have mentioned while c equal to equal to one now if you press zero it will come out of the loop Now, let me show you first entering one Okay, I've written one then and just press Enter see what it prints it prints token number one may please come in, but this should not be the case there should be written as token number two main please come in for that what we need to modify now before modifying it.
Let me show you if I press zero, then what happens. So if I press 01 here, then see what happened, the loop ended, the program came out of the loop and it ended the program over there. Now to make it correct, or to make it token number two, every time you press one, and the next token number will come up. To make it like this, what we need to do is, so let me just copy the code from here and paste it over here. So, what I need to do is, I need to increment this in value, because this n value should change every time I press one, so I need to increment n by one. So n equal to n plus one.
Every time the loop executes, n will be incremented by one and then in last, if you print zero, there should be a message at least So there should be something like this. Thank you. See you tomorrow. Okay. So this should be the message if all the patient is treated and now no patient is left to be treated and you want to close your chamber. So the last message will be Thank you see you tomorrow.
Okay, so now if I execute this code What will happen now we would execute this I'll give a welcome message over here. So now here I'll print hello everyone. We are starting. So this is the welcome mat. Now everything is perfect, I think hope you understand what is going on. So just press or execute the code.
See Hello everyone we are starting. So, the first token number will be by default token number one may please come in because n is equal to one, it takes the value one c is equal to one take up the value one it entered the loop and then it print this statement token number one may please come in and then in the next step it is asking if you have created your first question, then whether you want to continue or no now, if you press one, it will enter the loop and it will execute on this statement and again it will ask you to input the next number or whether you want to continue or not. Now, if you press zero, this loop will be closed and it will come out of the loop the program will come out of the loop and to print this statement.
Now, let me show you if I press one what happened now I'm pressing one and press Enter See what happened token number two may please come in. So, it's now working. So, every time it will ask you for input and if you press one, see token number three may please come in. Now, if you go on treating your patient like this, so, token number four may please come into the number five may please condom You are a busy doctor you have a very round doctors you have a lot of patient. So, you are treating your patient like this. So, you have a lot of patient suppose you are treating your 20 patient each day.
So, okay number 20 may please come in. So on the 20 patient are now treated. Now you want to close your chamber because all the patient is treated and no patient is left. So now, you will press zero, that you are done. You are done for today and you want to close your chamber. So, now continue.
So you press zero now whenever you place zero and press enter, see what happened. Friends Thank you. See you Tomorrow so whenever you press zero the program will come out of the loop it will not enter this loop because it will enter only if c is equal to equal to one, it didn't enter the loop and it directly printed this statement this statement of this print statement is out of the while loop because it is not indented. Whenever it is indented, then it will be a part of the while loop or any loop but it is not indented. So this print statement is out of the while loop. Now whenever I press zero, it will print directly this statement.
Thank you see you tomorrow. So this is quite interesting, I think so I suggest you to practice this program repeatedly. So all your doubts will be cleared. So this is a while loop. I hope you will practice because I think in programming you need a lot of practicing unless and until everything is clear to you. So keep practicing.
See you in the next video. Thank you