1 00:00:00,000 --> 00:00:01,800 [no audio] 2 00:00:01,800 --> 00:00:03,600 Friends, here we are going to discuss 3 00:00:03,600 --> 00:00:06,000 about 'if-else' conditional statement. 4 00:00:06,400 --> 00:00:09,500 So before going to enter with your 'if-else' conditional statements, 5 00:00:09,900 --> 00:00:12,700 already, we know simple 'if' condition, right? 6 00:00:13,000 --> 00:00:16,100 So, using that I want to write a small script, right. 7 00:00:16,200 --> 00:00:18,400 Let me open my editor. 8 00:00:19,100 --> 00:00:21,200 So here I am going to use Sublime Text Editor. 9 00:00:21,200 --> 00:00:22,600 You can use any editor. 10 00:00:24,000 --> 00:00:27,200 Let me give some name for my Python Script. 11 00:00:27,200 --> 00:00:29,800 The name is, convert into title format, 12 00:00:30,000 --> 00:00:31,800 so 'get_title_format'. 13 00:00:31,800 --> 00:00:35,210 [no audio] 14 00:00:35,200 --> 00:00:38,200 'get_title_format.py'. 15 00:00:38,200 --> 00:00:40,200 [no audio] 16 00:00:40,200 --> 00:00:42,800 So my intention is, I want to read 17 00:00:42,800 --> 00:00:45,000 some string. That string, 18 00:00:45,100 --> 00:00:48,200 I want to convert into title format. 19 00:00:48,200 --> 00:00:49,400 Right. First, let me write that. 20 00:00:49,400 --> 00:00:51,910 [no audio] 21 00:00:51,900 --> 00:00:53,100 'usr_str', 22 00:00:53,200 --> 00:00:55,300 I'm taking a variable called 'usr_str'. 23 00:00:55,500 --> 00:00:57,000 So, I want to read a string. 24 00:00:57,000 --> 00:01:00,000 So, if you want to read a string, you have to take always 'input( 25 00:01:00,000 --> 00:01:02,100 "Enter your string: ")'. 26 00:01:02,100 --> 00:01:04,099 [no audio] 27 00:01:04,099 --> 00:01:06,200 That's it. Then after that, simply 28 00:01:06,200 --> 00:01:11,300 what I am doing is, I am printing your 'usr_str.title()'. 29 00:01:11,300 --> 00:01:14,600 You know, if you want to convert any string into title format, 30 00:01:14,600 --> 00:01:16,600 there is a string operation called 'title()'. 31 00:01:17,600 --> 00:01:21,300 Right. Let me open my command line. 32 00:01:22,800 --> 00:01:27,000 Right. So, we have our scripts on 'Desktop\PythonScript'. 33 00:01:27,000 --> 00:01:28,400 So here our script is 34 00:01:28,400 --> 00:01:31,300 [no audio] 35 00:01:31,300 --> 00:01:35,100 'get_title_format.py'. See that script. 36 00:01:35,100 --> 00:01:36,800 We have only two lines of script. 37 00:01:37,600 --> 00:01:40,600 If you run your script it will run from top to down. The very 38 00:01:40,600 --> 00:01:43,000 first line is 'usr_str=input'. 39 00:01:43,000 --> 00:01:47,200 So because of this your script will ask something like, 40 00:01:47,200 --> 00:01:49,200 "Enter your string:" Let me run this. 41 00:01:50,100 --> 00:01:54,400 Yes, it is asking. I am going to provide 'python scripting'. 42 00:01:54,400 --> 00:01:56,600 [no audio] 43 00:01:56,600 --> 00:01:59,600 So now if you press enter on your keyboard, what will happen? 44 00:01:59,600 --> 00:02:02,000 Whatever the data you are providing here, 45 00:02:02,000 --> 00:02:05,800 that data will go and store into this variable. And in the next 46 00:02:05,800 --> 00:02:08,900 step what we are doing? So, this line is over. 47 00:02:08,900 --> 00:02:12,400 If you press 'Enter', this line is over. Then after that, simply 48 00:02:12,400 --> 00:02:15,200 your Python is going to print your given string, 49 00:02:15,200 --> 00:02:19,100 I mean 'usr_str'. That string is converting into title format, 50 00:02:19,100 --> 00:02:20,900 then it is printing. See the output? 51 00:02:21,400 --> 00:02:24,900 Yes, you are getting 'Python Scripting', capital 'P' and capital 'S'. 52 00:02:26,000 --> 00:02:27,000 This is fine. 53 00:02:27,800 --> 00:02:33,400 But, before converting into title format, the script has to 54 00:02:33,400 --> 00:02:37,400 ask like, "Do you want to convert this script into title format or not?" 55 00:02:38,400 --> 00:02:42,600 If I say 'yes', then only it has to convert. If I say 'no', it 56 00:02:42,600 --> 00:02:46,000 won't convert, but it has to print the given string as it is. 57 00:02:46,000 --> 00:02:48,000 [no audio] 58 00:02:48,000 --> 00:02:52,300 See that. What I am doing? Then I am taking user confirmation 59 00:02:52,300 --> 00:02:56,800 as a variable, 'usr_cnf', and I want to read 'yes' or 'no'. 60 00:02:56,800 --> 00:02:57,900 'yes' or 'no' is a string. 61 00:02:57,900 --> 00:02:59,400 That's why again, I am taking 'input'. 62 00:03:00,900 --> 00:03:02,600 "Do you want to convert 63 00:03:02,600 --> 00:03:06,400 [no audio] 64 00:03:06,400 --> 00:03:07,600 your given string 65 00:03:09,200 --> 00:03:11,200 into title fmt? 66 00:03:12,800 --> 00:03:13,800 Say yes or no." 67 00:03:13,800 --> 00:03:18,900 [no audio] 68 00:03:18,900 --> 00:03:19,900 That's it. 69 00:03:20,800 --> 00:03:26,500 Right. Now, if user says 'yes' then only I want to convert the 70 00:03:26,500 --> 00:03:29,400 data into title format, and then I want to display. 71 00:03:31,000 --> 00:03:34,600 So, two lines. First line is reading a string, second line is getting 72 00:03:34,600 --> 00:03:36,000 confirmation from the user. 73 00:03:37,000 --> 00:03:40,600 Right. So, whatever the user is going to enter, I mean either 'yes' 74 00:03:40,600 --> 00:03:44,500 or 'no', that we are storing into this variable. Now I am checking 75 00:03:44,500 --> 00:03:49,500 with 'if' condition, 'if usr cnf=="yes"', 76 00:03:50,500 --> 00:03:53,700 then only I want to execute this line. That is 77 00:03:53,700 --> 00:03:55,800 [no audio] 78 00:03:55,800 --> 00:04:01,500 this line, if user says "yes", then this value becomes 'True' 79 00:04:01,500 --> 00:04:05,100 no, because user is entering "yes", and that value 80 00:04:05,100 --> 00:04:07,200 we are storing into 'usr_cnf' variable. 81 00:04:07,200 --> 00:04:10,800 Now we are checking 'usr_cnf', and this direct string, 82 00:04:11,100 --> 00:04:14,900 are they equal? If user entered "yes", then yes, definitely 83 00:04:14,900 --> 00:04:16,899 this is equal. If it is equal, 84 00:04:16,800 --> 00:04:21,300 then this 'if' is allowing to execute this line by your Python. 85 00:04:22,700 --> 00:04:25,500 That's it. Right. First see the output. 86 00:04:27,000 --> 00:04:28,300 So, let me clear my screen. 87 00:04:28,300 --> 00:04:29,800 Let me open your script. 88 00:04:30,900 --> 00:04:35,100 Now I am going to run. So, whenever if you run you know it is 89 00:04:35,100 --> 00:04:38,500 going to execute from top to down. Very first line. See the 90 00:04:38,500 --> 00:04:41,000 output. First line executing, "Enter your string". 91 00:04:41,100 --> 00:04:43,200 I am entering 'python scripting'. 92 00:04:44,400 --> 00:04:46,400 Then it is asking, because of second line, 93 00:04:46,500 --> 00:04:49,200 "Do you want to convert your given string into title fmt? 94 00:04:49,200 --> 00:04:53,400 Say yes or no?" Let me type "yes", 95 00:04:53,400 --> 00:04:54,900 and I am pressing 'Enter'. 96 00:04:54,900 --> 00:04:57,800 So whenever if you hit 'Enter' on your keyboard, what will happen? 97 00:04:57,800 --> 00:05:02,100 This 'yes' value will go and store into this. That's over. Then 98 00:05:02,100 --> 00:05:04,300 two lines are over. Then your Python immediately 99 00:05:04,300 --> 00:05:06,200 goes to third line. This is the third line. 100 00:05:06,200 --> 00:05:07,900 So now you are entering "yes". 101 00:05:07,900 --> 00:05:10,400 This 'yes', and this 'yes', both are equal. 102 00:05:10,400 --> 00:05:11,600 That's what we are checking here. 103 00:05:11,600 --> 00:05:15,300 If they are really equal, then this value becomes 'True'. 104 00:05:15,300 --> 00:05:19,700 If it is 'True', then this 'if' will allow to execute this 105 00:05:19,700 --> 00:05:22,200 line, that's why, see the output. 106 00:05:22,200 --> 00:05:23,600 You are getting in title format. 107 00:05:23,600 --> 00:05:26,000 I mean capital 'P' and capital 'S'. 108 00:05:26,000 --> 00:05:28,400 Now, let me rerun and I am providing 109 00:05:28,400 --> 00:05:29,800 simply 'python scripting' once 110 00:05:29,800 --> 00:05:35,300 again. But I am saying 'no'. No, you're not getting any output. 111 00:05:36,500 --> 00:05:40,800 See whenever if you enter 'no', you know 'no' is going to store 112 00:05:40,800 --> 00:05:41,900 into this variable. 113 00:05:41,900 --> 00:05:46,700 Now in your hand this variable is like 'no', 'no==yes'. No, 'False', no. 114 00:05:46,700 --> 00:05:48,800 'no==yes', 'False' 115 00:05:49,300 --> 00:05:54,000 If it is 'False', then 'if' condition does not allow to execute this line. 116 00:05:54,000 --> 00:05:55,600 That's why you're not getting any output. 117 00:05:56,600 --> 00:05:59,600 But my requirement is, even 118 00:06:01,000 --> 00:06:04,500 though if you enter 'no', at least I have to get normal string 119 00:06:04,500 --> 00:06:08,200 display. I mean the string whatever you are giving same string 120 00:06:08,200 --> 00:06:11,200 I want to get, if I say 'no'. If I say, 'yes' I want to get 121 00:06:11,200 --> 00:06:13,500 in the title format. Right. 122 00:06:13,500 --> 00:06:16,100 So that's why what I am doing is, I am going to add one more 123 00:06:16,100 --> 00:06:21,350 'if condition, 'usr_conf=="no":' 124 00:06:21,350 --> 00:06:23,477 that means user is not willing to 125 00:06:23,477 --> 00:06:26,100 convert their given string into title format. 126 00:06:26,100 --> 00:06:29,400 Then at that time simply directly print your given string 127 00:06:29,400 --> 00:06:30,400 as it is. 128 00:06:31,500 --> 00:06:36,600 That's it. Right. Now, see the output. 129 00:06:35,400 --> 00:06:38,510 [no audio] 130 00:06:38,500 --> 00:06:41,200 'type get_title_fmt', title format. 131 00:06:41,200 --> 00:06:44,500 Let me run this script, and see the result. 132 00:06:44,500 --> 00:06:45,900 I am giving suppose 133 00:06:47,400 --> 00:06:48,400 "welcome to 134 00:06:48,400 --> 00:06:50,400 [no audio] 135 00:06:50,400 --> 00:06:54,800 python scripting", and I want to convert this as a title format. 136 00:06:54,800 --> 00:06:57,000 That's why I am saying to my script please convert it. 137 00:06:57,000 --> 00:07:00,300 I'm entering "yes", then you are getting in title format. 138 00:07:01,100 --> 00:07:02,400 Then rerun, right. 139 00:07:02,800 --> 00:07:06,000 I am entering, "welcome to python scripting", but now I am saying 140 00:07:06,000 --> 00:07:10,300 "no". If I say "no", what will happen? You are getting as it is 141 00:07:10,300 --> 00:07:13,000 your string. Then how your script is working? 142 00:07:14,400 --> 00:07:19,000 First observe here. Whenever you say "yes", this is 'True', 143 00:07:19,000 --> 00:07:22,600 that's why you're executing this line. At the same time, whenever 144 00:07:22,600 --> 00:07:23,900 you are entering 145 00:07:23,900 --> 00:07:25,800 "yes", then this is 'False', no. 146 00:07:25,800 --> 00:07:27,400 "yes", you are comparing with "no", 'False'. 147 00:07:27,400 --> 00:07:31,700 That's why, this 'if' condition is executing this line whenever 148 00:07:31,700 --> 00:07:36,700 you say "yes", and this 'if' condition is not executing your 149 00:07:36,700 --> 00:07:40,900 line whenever you say "yes". That means if you say "yes", 150 00:07:41,700 --> 00:07:44,400 this condition is 'True', and this condition is 'False'. 151 00:07:44,400 --> 00:07:47,900 That's why this 'if' condition is executing this line, and 152 00:07:47,900 --> 00:07:51,800 this 'if' condition is not executing this line. That's fine. 153 00:07:51,800 --> 00:07:55,600 [no audio] 154 00:07:55,600 --> 00:07:59,000 Okay. Now, let, in the second case, you are entering "no", right. 155 00:07:59,000 --> 00:08:00,900 Whenever if we say "no", 156 00:08:00,900 --> 00:08:05,800 "no", this 'if' condition is becoming 'False', that's why this is not 157 00:08:05,800 --> 00:08:10,600 executing. And this 'if' condition is becoming 'True', that's why 158 00:08:10,600 --> 00:08:11,800 you're executing this line, 159 00:08:11,800 --> 00:08:13,800 I mean your Python is executing this line. 160 00:08:13,800 --> 00:08:17,100 That's why you're getting this one. 161 00:08:18,400 --> 00:08:19,600 Yeah, this is okay. 162 00:08:19,600 --> 00:08:22,200 Your script is working perfectly as per your requirement. 163 00:08:22,300 --> 00:08:27,800 But the thing is, guys if you say "yes", if you say "yes". Assume 164 00:08:27,800 --> 00:08:31,400 that if you say "yes", this condition will definitely become 165 00:08:31,400 --> 00:08:34,100 'True'. Then you are printing this line. 166 00:08:35,100 --> 00:08:37,400 At that time, you don't need to check this condition, right. 167 00:08:37,500 --> 00:08:40,500 Already user is saying "yes", then why you are checking for "no"? 168 00:08:42,000 --> 00:08:45,100 Right. If this is 'True', you don't need to check this condition. 169 00:08:45,100 --> 00:08:48,000 If this is 'False', then just check this condition. 170 00:08:49,299 --> 00:08:55,400 Right. So guys whenever if you have only two options like "yes" or "no", 171 00:08:55,900 --> 00:08:56,900 Like "yes" or "no". 172 00:08:58,400 --> 00:09:03,300 Whenever if you have only two options like "yes" or "no" at that 173 00:09:03,381 --> 00:09:07,200 time you don't need to write two separate 'if' conditions, simply 174 00:09:07,500 --> 00:09:09,900 you can write 'else' here. 175 00:09:09,900 --> 00:09:12,200 [no audio] 176 00:09:12,200 --> 00:09:13,600 Then how it is going to work? 177 00:09:15,600 --> 00:09:17,900 Nothing is there guys. Very simple. Observe that. 178 00:09:17,900 --> 00:09:19,800 in case if this condition 179 00:09:19,800 --> 00:09:24,400 is 'True', if this condition is 'True', your Python will execute this line. 180 00:09:24,500 --> 00:09:29,000 I mean, 'if' is allowing to execute this line, and if this condition 181 00:09:29,000 --> 00:09:32,800 is 'True' by default your Python is going to skip this part, 182 00:09:32,900 --> 00:09:34,300 Python won't check this one. 183 00:09:34,300 --> 00:09:36,900 [no audio] 184 00:09:36,900 --> 00:09:43,100 But in case if this condition is 'False', this result is 'False', 185 00:09:43,600 --> 00:09:46,800 you know 'if' is not going to execute this line. 186 00:09:47,300 --> 00:09:49,100 It is not allowing to execute this line. 187 00:09:49,800 --> 00:09:54,800 And if this is 'False', be clear, if this is 188 00:09:54,800 --> 00:09:59,000 'False', by default without checking any condition your Python 189 00:09:59,000 --> 00:10:02,400 will execute the 'else' block, in 'else' whatever you have 190 00:10:02,400 --> 00:10:06,100 the code, that code will execute without checking any condition. 191 00:10:06,100 --> 00:10:08,300 [no audio] 192 00:10:08,300 --> 00:10:14,100 Right. So, remember that when you have to take "if else". Whenever if 193 00:10:14,100 --> 00:10:18,700 you have only two possible values for your requirement, then 194 00:10:18,700 --> 00:10:19,900 only you have to take 'if' and 'else'. 195 00:10:19,900 --> 00:10:21,900 [no audio] 196 00:10:21,900 --> 00:10:24,100 See for user confirmation, as of 197 00:10:24,100 --> 00:10:26,800 now we are treating only "yes" or "no". If it is 198 00:10:26,800 --> 00:10:30,700 "yes", this line has to execute. If this is "no" by default 199 00:10:30,700 --> 00:10:31,900 we have to execute this line. 200 00:10:31,900 --> 00:10:36,100 So, if you take "if else", once again I am repeating, if you 201 00:10:36,100 --> 00:10:40,300 take "if else" condition, if whatever you're writing here, if 202 00:10:40,300 --> 00:10:43,500 that is 'True' your Python will execute this line, and your 203 00:10:43,500 --> 00:10:45,600 Python don't consider this part. 204 00:10:45,600 --> 00:10:49,800 If this is executing, your Python simply by default it will 205 00:10:49,800 --> 00:10:50,900 skip this part. 206 00:10:50,900 --> 00:10:55,800 You don't need to bother about that. In case if this condition 207 00:10:55,800 --> 00:11:00,900 is 'False' then only your Python will execute this line or 208 00:11:00,900 --> 00:11:05,800 the block which is there under your 'else' without checking any condition. 209 00:11:07,100 --> 00:11:11,200 Right. Let me take one more example so that it will be clear for you. 210 00:11:12,200 --> 00:11:13,800 Now I am going to comment this. 211 00:11:13,800 --> 00:11:15,900 Otherwise, I will write new script. 212 00:11:15,900 --> 00:11:20,210 [no audio] 213 00:11:20,200 --> 00:11:28,010 'find_greater_number.py 214 00:11:29,400 --> 00:11:32,700 See my intention is, I want to read two numbers and then 215 00:11:32,700 --> 00:11:34,700 I want to compare, so whatever 216 00:11:34,700 --> 00:11:37,000 number is higher, that number I want to display. 217 00:11:38,100 --> 00:11:41,900 See that. So to read your numbers you can take 'eval()' function, 218 00:11:42,800 --> 00:11:44,700 then 'input("Enter your number: ")'. 219 00:11:45,200 --> 00:11:47,500 So guys, if it is string don't take 'eval()' function. 220 00:11:48,400 --> 00:11:52,100 Right. No need of taking 'eval()' function if it is a string. If it is 221 00:11:52,100 --> 00:11:54,800 any value other than a string, then you have to use 'eval()' function 222 00:11:54,800 --> 00:11:58,900 in Python3. "Enter your first number". 223 00:11:58,900 --> 00:12:00,900 [no audio] 224 00:12:00,900 --> 00:12:05,400 Then, I'm going to take one more number from user, second number. 225 00:12:05,700 --> 00:12:11,400 Let's say 'b'. 'input("Enter your second number: ")'. 226 00:12:12,800 --> 00:12:16,100 That's fine. Now, see directly 227 00:12:16,100 --> 00:12:18,200 I can't display like, 228 00:12:19,200 --> 00:12:20,200 ' is 229 00:12:20,200 --> 00:12:25,400 [no audio] 230 00:12:25,400 --> 00:12:29,000 greater than ', I can't write directly in this way, 231 00:12:29,000 --> 00:12:32,800 right, because without knowing the relationship between your 232 00:12:32,800 --> 00:12:40,700 a and b, how can I say a is greater than b, or let's say one more line, 233 00:12:40,700 --> 00:12:43,014 ' is greater than '. I can't say, right. 234 00:12:43,000 --> 00:12:46,200 [no audio] 235 00:12:46,200 --> 00:12:48,900 Without knowing relationship between, without knowing your 236 00:12:48,900 --> 00:12:52,300 a and b values, I can't decide which statement I need to display. 237 00:12:53,500 --> 00:12:56,400 But if you remember, if you remember, you have 238 00:12:56,400 --> 00:12:58,500 comparison operators, right. 239 00:12:58,500 --> 00:13:00,300 Let me enter into my Python. 240 00:13:00,300 --> 00:13:02,700 [no audio] 241 00:13:02,700 --> 00:13:07,500 Let's say 3 < 2, sorry 4 <, any number, any 242 00:13:07,500 --> 00:13:09,556 number 4< 2, it's 'False'. 243 00:13:09,500 --> 00:13:13,200 Now I can take a = 4 and b =2. 244 00:13:13,200 --> 00:13:19,400 Now I am comparing a < b, if really a < b then you will get 'True', 245 00:13:19,400 --> 00:13:24,000 otherwise you will get 'False'. Then this 'True' or 'False' result, 246 00:13:24,000 --> 00:13:25,400 I can use in 'if' condition. 247 00:13:26,200 --> 00:13:29,200 Right. Whenever you are getting result as 'True', or 'False' 248 00:13:29,200 --> 00:13:32,400 always I can use that in my 'if' condition. That's why what 249 00:13:32,400 --> 00:13:36,900 I am doing here is, if I want to print this information, 250 00:13:36,900 --> 00:13:40,400 right, if I want to print this information, a value must be 251 00:13:40,400 --> 00:13:44,400 greater than b, that's why I can write here, 252 00:13:44,400 --> 00:13:49,000 'if a > b', if really 'a > b', this value will become 'True'. 253 00:13:49,000 --> 00:13:54,600 So, if it is 'True', be clear guys, if the result of a > b 254 00:13:54,600 --> 00:13:57,200 is 'True', then only I want to display this line. 255 00:13:57,200 --> 00:13:59,700 [no audio] 256 00:13:59,700 --> 00:14:03,600 Right. 'if a > b' then only, I want to display 257 00:14:03,600 --> 00:14:09,200 this line. The same way suppose 'if b > a' 258 00:14:10,000 --> 00:14:11,400 then I want to display this line. 259 00:14:11,400 --> 00:14:13,700 [no audio] 260 00:14:13,700 --> 00:14:15,400 Right. So, what I'm doing is 261 00:14:15,400 --> 00:14:17,400 [no audio] 262 00:14:17,400 --> 00:14:21,300 if, if really a > b then definitely you'll 263 00:14:21,300 --> 00:14:24,900 get a 'True'. If it is 'True', then you are going to execute this 264 00:14:24,900 --> 00:14:31,000 line. Then it will work. The same way, if b > a, 265 00:14:32,600 --> 00:14:33,900 then I can print this line. 266 00:14:35,100 --> 00:14:38,520 Now it will work, but see the result. 267 00:14:38,520 --> 00:14:48,030 [no audio] 268 00:14:48,000 --> 00:14:51,200 So, our script name is 'find_greater_number', right. 269 00:14:51,800 --> 00:14:57,100 So, I am going to run this. I am giving numbers like 5 and 9. 270 00:14:57,100 --> 00:15:01,600 Yes, 9 is greater than, I'm taking I think both are 'b' values here. 271 00:15:01,600 --> 00:15:04,000 Yeah, here I need to write variable 'a'. 272 00:15:04,000 --> 00:15:06,310 [no audio] 273 00:15:06,300 --> 00:15:09,300 Now see that, I'm entering first number as suppose some 5 274 00:15:09,400 --> 00:15:12,200 and second number as 9, you are getting 9 > 5. 275 00:15:13,000 --> 00:15:18,100 Let me take 3 and then 1. 3 > 1. It's 276 00:15:18,100 --> 00:15:18,814 working perfectly. 277 00:15:21,400 --> 00:15:27,400 Right. Now, instead of writing a > b and b > a 278 00:15:27,477 --> 00:15:28,500 suppose, just assume, 279 00:15:28,500 --> 00:15:30,000 it's not perfect, 280 00:15:30,000 --> 00:15:34,400 If a > b, I want to display this information 281 00:15:34,400 --> 00:15:38,500 if it is 'False', then I'm going to display this information. 282 00:15:39,800 --> 00:15:44,300 It is correct up to a certain point. That is, just observe that. 283 00:15:44,300 --> 00:15:45,900 I am entering in this way. 284 00:15:45,900 --> 00:15:47,100 [no audio] 285 00:15:47,100 --> 00:15:49,400 4 and 5. What happened? 286 00:15:49,400 --> 00:15:53,000 Yeah, sorry. It's my bad. 287 00:15:53,800 --> 00:15:57,000 I'm entering number 5, and then I entering some number 288 00:15:57,000 --> 00:16:00,100 7. 7 > 5, it's working. 289 00:16:01,000 --> 00:16:03,900 Then I'm entering 7 and some 2, 290 00:16:03,900 --> 00:16:07,800 [no audio] 291 00:16:07,800 --> 00:16:09,900 7 and then 2. 292 00:16:09,900 --> 00:16:11,902 Yes, 7 > 2, it's working. 293 00:16:11,902 --> 00:16:17,200 But if I give both are same numbers 5 and 5. You're getting 294 00:16:17,200 --> 00:16:18,200 5 > 5 295 00:16:18,300 --> 00:16:19,800 That is not at all correct. 296 00:16:21,400 --> 00:16:22,900 Right. Now, see here. 297 00:16:22,900 --> 00:16:25,610 [no audio] 298 00:16:25,600 --> 00:16:29,500 When you have to take if and else? When you have to take if and else? 299 00:16:29,500 --> 00:16:35,200 If there are only two possibilities for your result, I mean for your value. 300 00:16:36,200 --> 00:16:38,800 See, if I take two values, 301 00:16:38,800 --> 00:16:44,000 let's say 2 and 3. Assume that this may be greater than 302 00:16:44,000 --> 00:16:48,200 this or maybe less than this or maybe equals to that, right. 303 00:16:48,200 --> 00:16:51,500 If you take two variables like 'a' and 'b', 304 00:16:51,579 --> 00:16:56,400 based on 'a' and 'b' values, a = b or a > b or 305 00:16:56,400 --> 00:17:00,100 b > a, three possibilities are there. Whenever 306 00:17:00,100 --> 00:17:03,800 you have three possibilities, you can't take simply 'if' and 'else' block. 307 00:17:05,000 --> 00:17:08,098 You can't take simply 'if' and 'else' block, then 308 00:17:08,000 --> 00:17:09,800 how you can write your code? 309 00:17:09,800 --> 00:17:11,800 [no audio] 310 00:17:11,800 --> 00:17:15,500 Right. See that. Now how I am going to manipulate this thing. 311 00:17:16,500 --> 00:17:19,000 See you can add in this way. 312 00:17:19,000 --> 00:17:22,800 'elif', if a < b, 313 00:17:22,800 --> 00:17:24,800 [no audio] 314 00:17:24,800 --> 00:17:26,000 Then I can write. 315 00:17:27,300 --> 00:17:31,000 b > a, or I can also write a < b, 'a' is 316 00:17:31,000 --> 00:17:34,000 [no audio] 317 00:17:34,000 --> 00:17:35,000 less than b. 318 00:17:36,500 --> 00:17:39,800 or else if maybe a==b, right. 319 00:17:40,200 --> 00:17:41,900 There is a chance to have an equal. 320 00:17:42,200 --> 00:17:44,599 So, at that time I can write. 321 00:17:44,599 --> 00:17:46,510 [no audio] 322 00:17:46,500 --> 00:17:48,800 Sorry, 'a' and 323 00:17:51,300 --> 00:17:57,200 'a' and 'b' are same, are equal. That's it. 324 00:17:57,200 --> 00:17:59,300 [no audio] 325 00:17:59,300 --> 00:18:05,000 Now guys, observe here. 'a' may be greater than 'b', or 'a' maybe less than 'b', 326 00:18:05,000 --> 00:18:09,281 maybe there is a chance to have 'a' and 'b' values are equal. 327 00:18:09,200 --> 00:18:12,200 That's why whenever if you have multiple possibilities 328 00:18:12,200 --> 00:18:16,200 while comparing your values, then you can extend your 'if' 329 00:18:16,200 --> 00:18:19,600 condition in this way. 'if', 'else if' one more condition, 'else if' 330 00:18:19,600 --> 00:18:21,600 one more condition, you can also write, if you have 331 00:18:21,600 --> 00:18:25,200 multiple possibilities you can also write one more 'else if'. 332 00:18:25,200 --> 00:18:28,200 [no audio] 333 00:18:28,200 --> 00:18:29,700 Right. Fine. 334 00:18:30,700 --> 00:18:31,700 Let me run this. 335 00:18:31,700 --> 00:18:34,510 [no audio] 336 00:18:34,500 --> 00:18:36,300 See, I'm entering 4 and 4. 337 00:18:37,600 --> 00:18:38,600 What happened? 338 00:18:39,600 --> 00:18:43,300 4 is less than 4, maybe 'a' and 'b'. 339 00:18:43,300 --> 00:18:45,000 Yeah. I have given 'a' and 'a'. 340 00:18:45,000 --> 00:18:48,300 It's my bad once again. Okay, see here. 341 00:18:48,700 --> 00:18:55,400 I'm entering number 4 and 4. 4 and 4 are equal. 4 and 7, or let 342 00:18:55,400 --> 00:18:58,500 me take some first higher number, second lower number. 343 00:18:58,500 --> 00:18:59,900 It's working perfectly. 344 00:18:59,900 --> 00:19:02,000 [no audio] 345 00:19:02,000 --> 00:19:04,000 Right. Fine. 346 00:19:04,500 --> 00:19:05,500 Now, see here. 347 00:19:05,500 --> 00:19:07,800 [no audio] 348 00:19:07,800 --> 00:19:08,800 Guys, first thing 349 00:19:08,800 --> 00:19:10,800 [no audio] 350 00:19:10,800 --> 00:19:13,000 you are having a simple 'if' condition. 351 00:19:13,000 --> 00:19:16,400 Second thing, whenever if you have two values for your required 352 00:19:16,400 --> 00:19:19,000 thing then at that time you can take if and else. 353 00:19:20,000 --> 00:19:22,800 But here whenever if you are comparing two values, right, you have 354 00:19:22,800 --> 00:19:25,800 three possibilities: first number greater than second number, 355 00:19:25,800 --> 00:19:28,400 or first number less than second number, or first number and 356 00:19:28,400 --> 00:19:29,700 the second number both are equal. 357 00:19:29,700 --> 00:19:35,500 So, at that time you can use if, else if, else if condition, right. 358 00:19:35,500 --> 00:19:36,900 And one more thing, 359 00:19:37,900 --> 00:19:39,500 here three possibilities, right? 360 00:19:40,000 --> 00:19:44,200 So, by this block, by this block, by these two conditions, you 361 00:19:44,200 --> 00:19:47,700 are checking greater than and less than. So if these two conditions 362 00:19:47,700 --> 00:19:52,300 are 'False', assume that, if these conditions are 'False' then 363 00:19:52,300 --> 00:19:54,300 by default, a and b are equal, right. 364 00:19:54,300 --> 00:19:57,100 So, at that time what you can do is simply you can write 'else' 365 00:19:57,100 --> 00:20:00,400 block. No need to check your condition, whether a==b or not. 366 00:20:00,400 --> 00:20:02,710 [no audio] 367 00:20:02,700 --> 00:20:06,300 Why I am writing 'else'? If it is right in this way, 368 00:20:06,300 --> 00:20:08,400 it's okay, no problem. It's okay. 369 00:20:08,400 --> 00:20:10,800 It will work perfectly. Without any confusion 370 00:20:10,800 --> 00:20:12,000 it will work perfectly. 371 00:20:12,700 --> 00:20:17,500 But what I am saying is, assume that I am giving 'a' value 3 372 00:20:17,500 --> 00:20:18,500 and 'b' value 4. 373 00:20:18,500 --> 00:20:21,400 [no audio] 374 00:20:21,400 --> 00:20:25,300 Yeah, first I will do this thing. 'a > b'. 'a' value 375 00:20:25,300 --> 00:20:31,000 3 and 'b' value 4. This is 'a' and this is 'b'. 'a> b'? No, 'False'. 376 00:20:31,000 --> 00:20:35,900 If this is 'False', your Python will skip this line because 377 00:20:35,900 --> 00:20:39,000 'if' doesn't allow to execute this line. Then immediately your 378 00:20:39,000 --> 00:20:42,200 Python will come to second condition. Here it will check. 379 00:20:43,200 --> 00:20:44,500 'a < b', yes, 'True'. 380 00:20:44,700 --> 00:20:48,200 If it is 'True', your Python will execute this line and remaining 381 00:20:48,200 --> 00:20:51,900 all remaining conditions your Python by default 382 00:20:51,900 --> 00:20:56,700 it will skip. It won't check. The first condition 383 00:20:56,700 --> 00:20:59,500 if it is 'True', remaining all conditions are going to skip 384 00:20:59,500 --> 00:21:01,700 whether they may be 'True' or not, 385 00:21:01,700 --> 00:21:03,900 you don't bother about that your Python is going to skip 386 00:21:03,900 --> 00:21:09,000 that, right. But in our case suppose as of now if I take 3 387 00:21:09,000 --> 00:21:11,200 and 3, both are equal. 388 00:21:11,200 --> 00:21:14,300 So, this condition definitely 'False', because you're checking 389 00:21:14,300 --> 00:21:17,400 3 greater than 3? No, 'False', because they both are equal. 390 00:21:17,400 --> 00:21:19,400 So, this is 'False', this is 'False'. 391 00:21:19,400 --> 00:21:23,400 So, whenever you have two values and greater than and less 392 00:21:23,400 --> 00:21:24,700 than conditions are false, 393 00:21:24,700 --> 00:21:28,200 then remaining option is equals to, equals only, right? 394 00:21:28,200 --> 00:21:31,600 That's why what I am saying is, you don't need to check this. 395 00:21:31,600 --> 00:21:34,300 So directly I can write 'else' here. 396 00:21:34,300 --> 00:21:39,700 So 'else' means, you know default block. When all above conditions 397 00:21:39,700 --> 00:21:44,600 are false then only 'else' will execute. When all above conditions 398 00:21:44,600 --> 00:21:46,800 are false then only 'else' will execute. 399 00:21:46,800 --> 00:21:50,500 So, if we take any two values which are equal for your first 400 00:21:50,500 --> 00:21:53,500 and second variable 'a' and' b', then this is 'False'. 401 00:21:53,500 --> 00:21:54,300 This is 'False'. 402 00:21:54,300 --> 00:21:58,600 That's why your 'if' is going to execute 'else' block by default. 403 00:21:58,600 --> 00:22:01,600 In case if any one of the conditions is 'True' that condition 404 00:22:01,600 --> 00:22:02,600 will execute. 405 00:22:02,600 --> 00:22:05,800 Otherwise, if all conditions are 'False', 406 00:22:05,800 --> 00:22:07,500 then only 'else' will execute. 407 00:22:09,000 --> 00:22:16,300 Right. Fine. So, guys this is all about simply your 'if-else' and 'if-else if' 408 00:22:16,300 --> 00:22:19,100 'else if' condition. Okay. 409 00:22:20,100 --> 00:22:22,600 So, in next video, we will write one simple 410 00:22:22,600 --> 00:22:27,940 script to understand effectively your 'if', 'else if', 'else if' condition. Okay. 411 00:22:28,376 --> 00:22:30,300 Okay guys, thank you for watching this video. 412 00:22:30,300 --> 00:22:36,864 [no audio]