DECISION CONTROL STATEMENTS - PART 1 (SIMPLE IF, IF ELSE) - PYTHON PROGRAMMING

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello friends welcome back to our channel so in the previous sessions we have discussing your various concepts in Python so in that we have already covered the various of operators in Python and now in this session let us move on to the control structures in so here first of all what is meant by the these control structures so this control structures means the name itself indicates these control structures says the control flow of the statements in the programming language so if we show the control flow we show the flow control so these are three types one is sequential decision control get ready to control so the sequential decision and iterative coming to this sequential and more muzzle sequential execution of the statements we call it as an sequential control that is if you want to add a two numbers so that requires a two integer so there is some two integers is equal to five musical decision print the a plus B so here the control flow sequential e so first line is attributed after that some file will be stored in a and second line is executed after that six will be stored in B and the third line that is not going to store that is I mean result will be displayed that is 11 will be displayed on the output screen so this is a normal sequential execution so a line by line execution so that we probably say sequential control flow so coming to this decision control flow the name itself indicates there will be some decision and based upon the decision the control will flow in one direction only in one direction so silly there will be some condition so based upon the clinician it will execute a true block or false block so the condition the condition means so relations between two operators so simply we can say relation between pullover that's like well we can we can say that if the relational operators are used in between two variables what the logical operators are used in between two simple conditions then we call that a car that has a condition or an expression so based upon the result of this condition of expression the particular block will be executed so if this condition on expression is true then some set of statements will be in truth it's and the other statements will be the skin and then condition or expression is false this - block will be skipped and the Holy Father block will be executed said that means if the control will flow only in one direction either true or supports next this is an iterative control structures so they try to control structures means loops that means executing some set of statements continuously until some condition or expression becomes first so multiple executions of a cell set of statements will call it isn't it make so let us see one by one so first we will cover this decision path of structures and then we will move on to this in try to control structures so first let us see the position from those structures right decision control structures so here in this decision terms of structures there are four categories one is simple if if s nested-if if/elif/else so there are four care for diabetes comes under this decision control structures one is the simple difference necessary if/elif/else so in this section Rizal about these two concepts and in the next session will be more do these two concepts now coming to this simple it so coming to the simple if here we have using the keyword if small let us write small letters if and simply we can say if is a true block similarly else is a false block and as I have said in the previously the decision control structures means we have to check the condition and based upon the result of that particular condition or expression the control will flow so if the condition is true to block will be executed for a response files block will be executed so here the question is where we have to write this condition of our expression so the conditional expression should always return in if block right so the condition or expression always it should be returned in if so if is a keyword and I else is also a keyword now let us see the syntax for this so here the name itself indicates simple if that means whether it is concentrate only on the true block so here if is nothing but your true block here we are using only if that place where only mentioning the truth we are just ignoring the pulse block so if the condition is true that particular block will be executed otherwise it will not execute anything the sequential execution will stacks right hope you understood this now how do represent a drop of statement so here see first and let us say the syntax Eve so I just lower case letters give forward by condition or etched expression so anything we can call it next expression : see it's not a semicolon you suggest a corner it's not a semicolon except just or next statement 1 statement 2 and so on statements any statement X right see this is a simple syntax for this simple if statement so again also we have to write a petition or its text expression and in this braum so as I have said that if is it true block so a block can be a single statement or algorithm statements so this block consists of a single statement or political statements so that depends on whatever was so how will represent a block of statements how to represent is block of statements so in C language simply we can find if condition and the rock of statements are represented in this curve increases so if you include these curly braces that implies all the rocks are are I mean how the statements are related to this if block similarly yes again we will write curly braces so well we have well we want to write multiple statements and whenever we want to combine all these multiple statements as a block will just represent all those multiple statements in curly braces in C language but here in Python language so we need not use this curly braces so here everything will be done by foreign the indentation so this is very important in patna indentation so indentation means alignment so all the same set of statements with the multiple statements which represents a block will be arraigned in is equal alignment so will be written in it equal alignment right so for this in addition we have to include this column after the condition so here this one will call has header and these statements we call it as suit so every header should end with Corrin so if this heaven is end with Colin automatically in the next kind the full spaces will be ignored and from the fifth to space the statement will be written so automatically the cursor will skip these four spaces and the cursor always turns from the fifth to space so they immediately have for completion of this statement if you press ENTER again the person really comes again and the cursor will skip the five four spaces and from the fifth of space it will be displayed so from the fifth especially we are writing the statement so we can observe this so all these multiple statements are aligned in an equal path so this follows the equal alignment so this represents invitation which gives or which specifies the group of statements which specifies the block right so here we are not using any curly braces so this will be applied for all the effective statements or all the decision control statements so in Python in general we have to follow this indentation and the indignation group specifies the block of statements so how to specify or how to represent the block of statements and that can be done by including all and the header of this company so if you put this header I mean on and the header automatically the indentation will be followed so whenever you this dr. stateman automatically press the backspace so that the cursor will move to the first life I mean towards its left left a little bit better and this statement represents the immediate statements after this condition so that we have to observe by using these arrangements so if condition here there is an alignment right four spaces so this represents a block of statements and immediately after a I mean after completion of all these multiple statements security we have to press the backspace so that the cursor should be moving to the leftmost corner and from here it will again we have to write the statement so they say when is this statement is an immediate sequential statement excellence after the condition I mean after if the condition falls a this statement will be executed or if the condition is true after executing all these statements this caper will be so this is no matter has but because we have we we didn't write any else but only if condition so this is always simple right so hope you understood so let us see the program simple program so that you will so let us write the program so here my ready program whether the number is zero or nonzero C so first read the value so far really we have the right end is equal to here input off enter em right so this gives them string right as you have discussed in the input and output statements the input statement always gives the result as a string format so here we have to check in cell numbers so for this purpose we have to use the conversion type conversion so we have to convert this system to India so for converting this string to integer just add in right as a prefix further this string will be converted into again and that will be a same two yet now M is a numeric now we have to check whether the M is a non zero of Z so if y n is equal to is equal to zero fine so this is very very important so if you include this column automatically the cursor will start from here bring it zero okay so this is a simple program so we are not writing any else part or just we are reading the only if part that is a true part no let us move the next one that is offense offense so here then in the offense we have to use above the keywords if n else so he if he is a true block and else is a true and in France block so here based upon the text expression or the condition so the result of the text expression or a condition only one block will be executed the other one will be skipped so let us write the syntax here so here also we have to follow the indentation so if condition or text expression kourin so this is very important statement 1 so we can write whether it can consist of either single statement of include statements statement 2 and so on again else so this ends the to block because here we are reading then else but from leftmost corner right so this element should be same yes again we have to include the column so no military control or the castle will start it blinking from this element that means if you leave the four spaces and it will start blinking all the evolution so statement 1 statement 2 in so on statement X see here this condition or it expects text expression so this is called a true block and this is called a false grow right so if this condition is true automatically all the statements comes under the true block will be executed and this part will be ignored so it will not be executed and if this condition or next expression is false article if these statements will be ignored and ultimately the control will move on to this else part because it's a pulse bomb so this statement should be educated and half the completion of these if-else this statement X will be exhibited so stapled I am writing this statement X because it is a sequential execution if you achieved only after completion of this inference right so this is a sequential execution here most important thing once again I am Telling that is indentation so we have to follow this indentation that means we have to differentiate this header and suit with a condom so header column it automatically applies the indentation right so hope this you understood this one and I'm gonna see an example for this offense so let us check whether the given number is positive or negative positive or negative so first again common we have to read n value so input enter n value so it will return it is ten format so for this we have to I guessed so I have to convert into in digit now and value is an integer now right now if again greater than zero so if you have greater than zero obviously any number any number is greater than zero we know that it's a positive number so right now so if you improve this call the element will be applied so that is called indentation so print positive else so if it is face that means if that value is less than geo-print negative right so this is a simple program example program right from this simple defense so here we are reading the in value and we are checking the condition now text expression if it is a greater than 0 or less than G so if it is a greater than zero automatically we are pretty good size is a positive and if if it faiis already has for me today is good so we need not write the on poor condition here right so the important thing is this text expression or a condition should be written only beside the if statement so we should not write this conditional text expression beside the else part so else part is always the first block right so hope you understood this too so let us stop here and the next session will discuss about the remaining two decision control statements that is nested if & if/elif/else so hope you understood this simple concept if you really understood my videos like my videos share my sessions to your friends and if you are having any doubts regarding this Python so feel free to post you in the comment section so that I will definitely try to clarify all your doubts so don't forget to subscribe to our channel so keep following my sessions thanks for listening thank you very much
Info
Channel: Sundeep Saradhi Kanthety
Views: 65,719
Rating: 4.9011583 out of 5
Keywords: SUNDEEP, SARADHI, KANTHETY, PYTHON, PROGRAMMING, HIGH-LEVEL, LANGUAGE, PORTABLE, FEATURES, APPLICATIONS, INSTALLATION, INTERPRETER, PYTHON SHELL, PYTHON SCRIPT, INTRODUCTION, BEGINNERS, GUI, GAMING, WEB DESIGNING, PYTHON 3.7.0, PLATFORM INDEPENDENT, PYTHON BASICS, OPERANDS, RELATIONAL, LOGICAL, AND, OR, NOT, EXPRESSION, control structures, sequential flow, decision control, iterative control, simple if, if else, nested if, if elif, true block, false block, test expression, indentation
Id: CcfCNrKrto8
Channel Id: undefined
Length: 22min 22sec (1342 seconds)
Published: Fri Aug 03 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.