Python Tutorial #7| LARGEST SMALLEST PROGRAM | WHILE | IF ELSE | Tagalog | English | Filipino | 2021

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hi everyone welcome to the coding channel today is the seventh episode of our python tutorial series for beginners and in this episode we are going to talk about how to build the largest and smallest program in python is more when we come back [Music] [Applause] [Music] and welcome back now in this episode we are going to create a program that will prompt the user to enter 10 integers then find the largest and the smallest of 10 integers input normally this type of problem is the most one of the most frequently uh asked questions for the um uh you know beginners like you now um but if you know how to solve this type of problem so i suggest that you pause for a while the possible you post this video for a while and then you get your laptop and then join me okay you start solving this problem and then after that let's try to compare our uh answers later okay but if you're just planning to just watch it uh for now so join me as i solve this um problem okay so um let's start now uh we will begin if i'm going to uh create a program okay or to solve this type of problem so i will start um creating my loop since there we are task to ask the user to enter 10 integers right so i will start in the initialization of my loop okay so for example i will be using the counter variable i will initialize it to one and then uh next so this would be my initialization okay if i'm going to put the inline comment there so i'll just have to put them um and a white spaces there one two spaces and then after the number sign just put one a space again okay and then the initialization okay so that is the um the standard way of doing that okay and then just to have a cleaner code okay and then if you are using also a pie chart as you can see there is a weak warning so later we will try to make this as a zero warning okay so normally these are warnings that um these are not a syntax error okay but uh we need to follow okay just to have a cleaner code okay next so after the initialization okay i will be using the while and then uh let's try to loop while counter is less than or equal to how many times so let's say for example 10 so make sure okay you put as a white space there at least one blank space and then followed by the value and then the column okay that's it so this is now a condition next after that uh we will have an input statement here well prior to that let's just complete first beyond the the while a syntax so we know we now have the initialization we have the condition and we have the um increment okay so for example since we've used a counter here so make sure that you use also the counter variable plus equals okay and then one meaning we will add one to the counter variables this will serve now as our um increment so this one is a complete um syntax of our while okay it will let us now iterate ten times okay now what's the statement inside of our wire we will prompt the user to enter 10 integers so we will have an input statement okay so just to have this input statement what are we going to do for example we will use number variable is equal to uh input right but we all know that using input since we are uh going to store an integer variable so whatever you type in the console of the in python uh that is a string by default so we will need to cast or convert temporarily the the string input to integer okay to prevent an error so enter for example a number and then number and then i just have to use um a concatenation here i will be using the counter variable so that uh it will generate number okay enter number one number two number three number four and so on okay but take note uh every time we use this um okay i mean every time we concatenate uh an integer or any a data type a string okay just to make this whole um expression okay or a statement for example to make it string all string so we will use the string um the string keyword there or the str keyword just to temporarily convert okay and then let's have another column here okay and another closing parenthesis there there you go so this is now an example of my input statement i normally just put those comments there okay now after the input statement what are we going to do okay let's try to run okay just for you to see okay so enter number one for example we have 89 67 45 34 23 99 88 77 66 and then for example a four so that's it okay so far so good okay so let's continue what else our major task is to find the largest and smallest of this 10 numbers input so how are we going to make it possible so there is a decision making right so so if there's a condition okay that we're going to make so we will be needing if so there are a lot of options so we can use uh both uh okay for example two if statements or if and if okay so like for instance i will be using only if okay just to separate the the largest and then the smallest so that is also possible but before that okay um since we don't have any initial value here okay or um it could be better to to trip the first input as the first i mean as the as the largest and smallest at the same time right so how are we going to tell python to to do that so if uh the value counter is equal to one okay so what are we going to do if the valid counter is equal to one if the first input for example so we will consider the first input as the largest and also the the smallest okay and then equals what zero okay so that's the syntax in again another if you remember the syntax in python if you're going to assign zero both to largest and smallest so we can do like this okay so next so if counter is equal to one largest is equal to smallest okay is equal to zero what about if what okay so if um this time what if you are now in the second iteration so if the user have entered for example five okay so that would be the initial value of largest and then smallest okay so uh if the user have entered 10 for example the second time around so we're talking of 10 5 and 10. so we will compare now so if number if the new input is greater than the largest so far right if greater than the largest so far what are we going to do we will assign um that number to largest if it is true right okay so what about if that number is um uh less than the smallest so far so that's the time that you will also have a condition there if a number is less than the smallest so far then you just have to put a column there okay now if you have noticed that there is a um what they call this underline in largest and smallest okay even though i'm sorry uh okay we have an error here why uh if counter is equal to one what i'm trying to say here is that the value of largest and smallest is the value of number okay because we treat as the first input is the largest and smallest so far okay sorry about that now um speaking of this variable having the underlines these are actually uh what uh warnings okay so if you're going to use um a variable uh for let's say an output okay or in our condition so we will just uh make sure that uh we um initialize this variable so if you can see here okay name largest for example can be undefined so there is a possibility that that is undefined so that is why this is to make sure outside we will have um a an initial value let's say let's try to put a zero there okay so we have a largest or a smallest equals a zero okay it's better like that just to initialize see as you can see uh you can see in the the underlying the thing there in largest and smallest now okay so okay let's continue if number is less than smallest so smallest is equal to number right so we we we dropped now there if there's a possibility that the given number is less than the smallest so far so we will assign the number to smallest okay so since i've used the uh alt here so as you can see uh python wheel uh every iteration on python will test uh this if this three if unconditional okay but it is it's okay um it's because um since we are going to display the largest and smallest so that would be fine okay but if you're going to use the if and if so later in our next example i will be using the if okay just for it to have a lot of options okay now we're done with the initialization we're done with the condition okay so our next step just to um finish this um problem our program is what is an output statement okay so uh when are we going to display the output let's say the largest is the the smallest is once the condition is already false okay so now based on what we have learned from our previous episode we can use else statement in while right okay so if you're going to use else so that the the codes that we are going to um insert in inside of the uh else um you know statements uh our python will execute those statements after or when the condition of our while is already false remember that okay so that's why it's appropriate to place the output statement here in s so let's say for example the largest is the largest is a comma then where did we put the largest on a value inside of the largest variable so the output is something is like this and then let's try to have another or the smallest sorry okay so the smallest is this time smallest okay so that's it after a while so let's try and take note we still have a what warning here okay missing white space around operator six okay operator in line number six white space uh here let's see that is a um small uh you know weak warning okay so again missing white space around operator what else blank line at the end of file 24 okay so let's try since uh we don't need this one and we want to have a zero warning okay missing white space around operator six again where okay here see after the equal sign just have to put the white space there so there you go okay so if you're using python again and then if you can see that the check here so it only means that we don't have um any um warnings so we follow the um the standard format the naming convention okay the space spaces for example using white spaces and all that okay so there you go let's run so enter number one okay for example we have 90 89 78 95 96 99 94 okay 1903 92 and um say 12. okay you want to press the enter key so the largest is 99 and the smallest is 12. let's double check okay 99 the largest and the smallest is 12. okay so that's it that's how we solve the largest and um the smallest okay now what if we're going to modify this program okay because this um iteration or this uh loop is only limited to 10 okay so what if we allow the user to enter as many number as uh they want to enter okay and then um the program will terminate once they have entered a sentinel value or let's say negative one okay just to uh terminate the program or just to make the the while condition false okay so uh let me copy this one and in here i just have to pause this and then copy and paste here and then let's try to modify okay so how are we going to modify if we're going to uh talking of the sentinel control repetition okay first is we need to have an input statement okay let's try well if it's let's try to have an input statement there the input statement now is what let's say enter um enter enter a number okay we will not use this one anymore so enter a number okay enter a number negative one to exit for example okay so for a number or the enter negative one to exit as we all know that um we need to also enter a number okay so once the user have entered negative ones so the iteration will stop will exit or the program will exit something like that so are we um well just try to learn okay better to start from scratch okay start all over again okay because sometimes you know it's a very a good do what to start from scratch then editing uh something okay okay so input so now if you're going to use the while loop here with the sentinel controlled repetition or unknown number of repetition the input statement now will serve as the initialization so meaning it doesn't always uh works that i mean normally we we see the initialization as okay counter is equal to one counter is equal to five so that's the initialization right using assignment statement but that initialization could be an input statement okay so this one would serve as our initialization the the value of number okay because during the first iteration if the user will enter for example negative one so the the program will exit uh we'll exit we will not continue anymore okay that's why in our condition we will use the number here so while number is not equal to let's say negative one so we will continue i'm sorry i'm using the here parenthesis here so while number is not equal to negative one okay so what are we going to do oh we are going to what um let me just have that uh trip the first input as the largest and the smallest so far so again we will need the largest is equal to smallest is equal to number okay and then after that let's continue with a while so while uh number is not equal to negative one and then what are we going to do uh just to complete the initialization the condition and then the increment so if you're going to use this type of um you know syntax we will treat anoth we will put another input statement inside of the while loop so this would serve as our increment okay the input statement but i will uh also serve as our again increment okay in here the input statement is also our initialization okay now so before we end the while so there should be an input statement to ask another input okay so that when we go uh back to the aware conditions so the value of number is now a new uh having a new value okay next so let's try what what's next while number is not equal to negative one what are we going to do okay we will use the if here so um since we already uh made a what an initial initialization for uh the first input we consider that already as the largest and the smallest so far so in here we will just have a uh an if statement so if a number is a greater than the largest so far so what are we going to do or again largest is equal to number okay and then or this time uh let's just use the alif for example so l if i'll just try to align alif here and if number is less than uh smallest okay so what are we going to do because every input okay we can also use the if alif here because every input there is a possibility that that input is the largest okay it's greater than the largest so far or there is a possibility that that input is less than the smallest so far so we can also use this type of um logic okay so smallest is equal to number okay but you cannot use the the else okay it's because yeah if for example if number is greater than largest and then you put else uh smallest is equal to number so it uh it doesn't mean that if that number is not greater than largest so it doesn't mean that that is the smallest so far so don't use else okay but instead just put another condition just to be you know safe okay so right now i'm showing you the if and if um version and this one is by using the if condition okay so let's try it let's try to continue so we now have the um the increment here we have the assignment statement and then we can also use again the uh the else okay so let me just copy this one because it's all the same and you just have to put it here the largest and the indus smallest let's try to run enter number one for example ah we're running the um the old one okay again you just have to point here and then run this new file okay so enter negative one to exit for example if you enter negative one okay so that's the end largest negative one the smallest negative one okay since the the condition is uh already false let's try to run again example we have nine six five seven eight three one and a two okay and then even zero okay but so when this when is uh when we're going to terminate this program if you're going to enter negative one okay that's it the largest is nine and the smallest is zero not including negative one okay because um one once we enter a negative one here so that would make the statement the condition false okay so that's it that's the version of a um the largest and smallest program by using the um unknown number of repetition of while written if ali okay i've seen some of the um warnings here so indentation is not a multiple of 4 line number 13. my number 13 indentation where nothing is not a multiple of 4 13 elite less than smallest okay what about this one over indented 13 over indented what's that nothing this one file why why we have an error okay so that's it just a small white space there over and then okay when you put it back so no more again that is okay that's it that's complete six seven eight negative one okay eight and then six okay now all for today and if you like this video please give us a thumbs up and consider subscribing and as always show your love through comments and favorites god bless and thank you for watching [Music]
Info
Channel: TheCodingChannelPH
Views: 266
Rating: undefined out of 5
Keywords: python, python tutorial, python 2021, python tutorial 2021, python tutorial tagalog, largest smallest program in python, python if statements, largest program python tagalog, largest smallest python, largest smallest python program filipino, while loop, while loop in python, loops in python, python largest smallest program, largest smallest python program, python if else programs, python if else tagalog, python while loops tagalog, python largest smallest program tagalog
Id: -i-sfOhLUy4
Channel Id: undefined
Length: 26min 40sec (1600 seconds)
Published: Thu Sep 02 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.