1 00:00:00,430 --> 00:00:04,650 Oh yes and welcome back to another class of our course about Python. 2 00:00:04,650 --> 00:00:11,250 The complete introduction I'm done now with some many things that can be used for you guys to create 3 00:00:11,280 --> 00:00:18,330 your own programs and they are going to talk about another very important thing about Python. 4 00:00:18,630 --> 00:00:24,420 So we are gonna talk about the if statement which is something that is very important for you guys to 5 00:00:24,510 --> 00:00:25,410 understand. 6 00:00:25,680 --> 00:00:27,780 If you want to create your own application. 7 00:00:27,780 --> 00:00:31,500 So what exactly we are going to talk about in this course in the next class. 8 00:00:31,500 --> 00:00:33,050 Well it's very simple. 9 00:00:33,180 --> 00:00:38,370 We in this class we are going to talk principally about what is the if statement how it works. 10 00:00:38,370 --> 00:00:43,020 We are going to talk about boolean variables since those are very important for you guys to be able 11 00:00:43,020 --> 00:00:49,860 to use the if statement because without boolean you are not able to work with if statement and we are 12 00:00:49,860 --> 00:00:54,840 going to talk about everything that is around if statements so we are going to talk about the OR and 13 00:00:55,110 --> 00:01:00,180 Elif and not so we are going to create some small apps around all this. 14 00:01:00,180 --> 00:01:04,080 So you guys will be able to understand what is it exactly and how it works. 15 00:01:05,340 --> 00:01:05,620 All right. 16 00:01:06,040 --> 00:01:13,270 So before we start in this subject we have to understand what is a boolean variable in this case it 17 00:01:13,270 --> 00:01:15,160 boolean variable is simply a variable. 18 00:01:15,160 --> 00:01:20,740 Well a boolean that a type start boolean that that is simply a data type that will have true or false 19 00:01:20,770 --> 00:01:20,970 in it. 20 00:01:21,550 --> 00:01:28,990 So basically we have strings that are text we have numbers that are well numbers and finally boolean 21 00:01:29,560 --> 00:01:31,930 which are true or false. 22 00:01:31,960 --> 00:01:34,630 So for the guys to understand let me write down something. 23 00:01:34,630 --> 00:01:38,710 Let me write down a variable and store a boolean that type. 24 00:01:38,890 --> 00:01:47,380 So in this case let's say I'll write down I want to keep and I store the value true. 25 00:01:48,090 --> 00:01:53,020 So in this case what Python understands Python understands that this that type which is I want to eat 26 00:01:53,980 --> 00:01:55,030 is equal to true. 27 00:01:55,090 --> 00:01:56,050 So I want to eat. 28 00:01:56,050 --> 00:01:57,460 Technically yes I want to eat. 29 00:01:57,460 --> 00:02:05,830 So this is true in the other case that say for example I want to drink I want to drink. 30 00:02:05,970 --> 00:02:08,330 This is another variable that we created in this case. 31 00:02:08,340 --> 00:02:09,880 Let's say it's false. 32 00:02:10,380 --> 00:02:13,890 So what Python understands but understands that this variable is true. 33 00:02:14,040 --> 00:02:20,190 So he will return a value in consequence of this and that is false so he will return something based 34 00:02:20,280 --> 00:02:22,470 on this answer. 35 00:02:22,770 --> 00:02:24,830 So how words that if statement. 36 00:02:24,990 --> 00:02:29,380 So how does a word that is very simple let's say something happens to you. 37 00:02:29,390 --> 00:02:35,790 So let's say a situation happens to you and or you are creating something and you expect a certain outcome. 38 00:02:35,790 --> 00:02:42,070 So you will ask yourself this question if this outcome appears I want this to happen. 39 00:02:42,270 --> 00:02:46,530 If it doesn't appear I want something else to happen to this. 40 00:02:46,530 --> 00:02:48,100 Exactly what Python will do. 41 00:02:48,150 --> 00:02:54,060 And this is exactly what we'll do with our if statement we can for example add some other things if 42 00:02:54,210 --> 00:03:00,720 this happens or this happens I want this outcome or if this happen and this happened I want this type 43 00:03:00,720 --> 00:03:03,000 of outcome. 44 00:03:03,050 --> 00:03:05,780 So that's exactly what we are going to do in this class. 45 00:03:05,780 --> 00:03:06,060 All right. 46 00:03:06,080 --> 00:03:09,080 So let's start this right now. 47 00:03:09,170 --> 00:03:15,290 So the first thing I'll ask you guys to do is simply write down if so when you wrote down if what we 48 00:03:15,290 --> 00:03:19,950 will want to do is write down are a variable in this case is going gonna be I want to eat. 49 00:03:20,000 --> 00:03:26,700 So if I want to eat is true. 50 00:03:26,760 --> 00:03:28,790 So in this case python on verifies automatically. 51 00:03:28,790 --> 00:03:33,200 So that's the way that we will ask ourselves if it's true. 52 00:03:33,230 --> 00:03:35,780 I want to print. 53 00:03:35,780 --> 00:03:36,530 Let's have a pizza. 54 00:03:36,590 --> 00:03:38,450 So in this case let's 55 00:03:43,330 --> 00:03:51,930 let's have a pizza and if we run the app Well as you can see based on the returns let's have a pizza 56 00:03:53,130 --> 00:03:55,560 so this is the condition the condition is. 57 00:03:55,560 --> 00:03:58,500 If I want to eat well bite on return let's have a pizza. 58 00:03:58,650 --> 00:04:00,620 So if for example here. 59 00:04:00,620 --> 00:04:00,840 Right. 60 00:04:00,840 --> 00:04:01,230 Don't. 61 00:04:01,230 --> 00:04:08,990 False instead of true right down false and we run our app as you can see nothing will appear because 62 00:04:09,590 --> 00:04:10,430 something will appear. 63 00:04:10,430 --> 00:04:13,420 Only if we have a true value here. 64 00:04:13,430 --> 00:04:18,200 All right let's say you want to say we want something to happen in the case that this is not true. 65 00:04:18,200 --> 00:04:22,840 So in the case that this is true I will return let's have a pizza. 66 00:04:22,850 --> 00:04:26,570 But in the case that this is not true I want something to happen. 67 00:04:26,570 --> 00:04:28,990 So what exactly you do is very simple. 68 00:04:28,990 --> 00:04:29,340 All right. 69 00:04:29,330 --> 00:04:34,460 Don't else and I will write down what I want to print so. 70 00:04:34,630 --> 00:04:39,610 Otherwise I want to return. 71 00:04:39,810 --> 00:04:40,690 I'm good. 72 00:04:40,700 --> 00:04:41,660 So in this case. 73 00:04:41,690 --> 00:04:42,990 Write down a good 74 00:04:46,250 --> 00:04:47,320 end if I want my app. 75 00:04:47,910 --> 00:04:49,770 Well it's gonna it's gonna print I'm good. 76 00:04:49,860 --> 00:04:56,010 So let's say I want to eat let's have some pizza and if I don't want to eat I will return. 77 00:04:56,010 --> 00:04:57,270 I'm good. 78 00:04:57,510 --> 00:05:07,460 So once again as you can see this is a way that we can use our well our if statement. 79 00:05:07,540 --> 00:05:07,780 All right. 80 00:05:07,810 --> 00:05:14,800 So another way that you guys can use it will be for example with if and so in this case we by on will 81 00:05:14,800 --> 00:05:23,320 verify 2 or three two or three or an infinity of variables before giving. 82 00:05:23,380 --> 00:05:31,350 Well the answer to in this case let's say for example if I want to eat and I want to drink or choose 83 00:05:31,420 --> 00:05:35,110 in this case I want to drink or two. 84 00:05:35,110 --> 00:05:43,380 So both of those variables are true this means that I want to return. 85 00:05:43,410 --> 00:05:49,010 Let's have a pizza and let's say a drink. 86 00:05:49,020 --> 00:05:51,900 So what Python will do Python will verify. 87 00:05:52,230 --> 00:05:54,180 First of all is it true. 88 00:05:54,240 --> 00:05:57,610 If yes he will verify is it is this variable true. 89 00:05:57,660 --> 00:05:59,210 If it's both of them are true. 90 00:05:59,370 --> 00:06:00,800 Python will print this. 91 00:06:00,840 --> 00:06:02,590 If not python will print I'm good. 92 00:06:02,940 --> 00:06:03,690 So let's verify it. 93 00:06:03,960 --> 00:06:05,250 That's right down true here. 94 00:06:05,340 --> 00:06:10,740 Just for you guys to understand and we run are up to in this case Python returns. 95 00:06:10,770 --> 00:06:14,010 I'm good because this is true but this is false. 96 00:06:14,010 --> 00:06:16,380 But if both of those variables are true. 97 00:06:16,430 --> 00:06:22,480 So in this case where on True and true as you can see python will return let's have a pizza a drink 98 00:06:22,540 --> 00:06:23,870 or and a drink. 99 00:06:23,920 --> 00:06:27,230 So we run the app as you can see Python already done here. 100 00:06:27,250 --> 00:06:30,930 Let's have a pizza and drink all right. 101 00:06:30,950 --> 00:06:38,780 So right now that you guys understand this next thing that we want to do is work with the if and the. 102 00:06:38,800 --> 00:06:46,060 Or so in this case python will verify if one of those variables is true. 103 00:06:46,120 --> 00:06:53,330 So what we want to do is we'll write down right here instead of writing down and we'll write down more. 104 00:06:53,660 --> 00:07:05,240 So if I want to eat or I want to drink I want Python to return let's go to the restaurant. 105 00:07:07,830 --> 00:07:13,970 And we run the up so in this case as you can see both are true. 106 00:07:13,980 --> 00:07:15,100 So python will return. 107 00:07:15,120 --> 00:07:16,240 Let's go to the restaurant. 108 00:07:16,290 --> 00:07:18,200 If only one of those is true 109 00:07:23,510 --> 00:07:27,920 so as you can see if one of those is true and we run our up Python we'll still return. 110 00:07:27,920 --> 00:07:29,190 Let's go to the restaurant. 111 00:07:29,340 --> 00:07:35,010 Since we have used the OR right here were a statement. 112 00:07:35,100 --> 00:07:38,270 If we change it by end it's not gonna work. 113 00:07:39,090 --> 00:07:42,610 Because we don't have both of them that are respected. 114 00:07:42,900 --> 00:07:50,610 But if we only write don't work it's gonna work because one of those one of those variables is equal 115 00:07:50,610 --> 00:07:51,120 to true. 116 00:07:51,180 --> 00:07:55,340 And this is what we ask Python to verify. 117 00:07:55,470 --> 00:07:56,470 All right. 118 00:07:56,580 --> 00:08:00,160 Right now that we understand all those things. 119 00:08:00,180 --> 00:08:05,830 The next thing that we are gonna ask ourselves is if for example one to verify another statement or 120 00:08:05,850 --> 00:08:15,420 in this case let's say for example we have I want to drink and let's say it's false if it's false. 121 00:08:16,130 --> 00:08:18,530 Let's say I want Python to verify something else. 122 00:08:19,160 --> 00:08:23,720 So in this case I want Python to verify if I want if I want to drink. 123 00:08:23,720 --> 00:08:27,160 So in this case Python verified if I want to eat and it's false. 124 00:08:27,310 --> 00:08:30,560 So let's say right now I want Python to verify if I want a drink. 125 00:08:30,560 --> 00:08:37,550 So how exactly I will add the if statement in and Naif statement that already exists. 126 00:08:37,550 --> 00:08:38,450 So it's very simple. 127 00:08:38,450 --> 00:08:42,850 I will use the L if so in this case. 128 00:08:42,920 --> 00:08:49,910 Elif when I use the Elif in an if statement it's simply I add a if statement statement inside of another 129 00:08:50,000 --> 00:08:51,250 if statement. 130 00:08:51,410 --> 00:08:53,000 So let's say this value is false. 131 00:08:53,120 --> 00:08:57,740 So I will use the Elif and in this case I will write down my function. 132 00:08:57,750 --> 00:09:06,680 So I want to drink and I will verify if I want to drink. 133 00:09:06,770 --> 00:09:09,480 So if yes I want to drink what I will do. 134 00:09:09,950 --> 00:09:10,970 It will simply print 135 00:09:14,510 --> 00:09:16,460 let's have a drink. 136 00:09:20,180 --> 00:09:22,180 Let's have a drink. 137 00:09:23,810 --> 00:09:26,580 All right and otherwise 138 00:09:30,020 --> 00:09:51,110 in this case I'll write down my else on the print I'm good. 139 00:09:51,320 --> 00:09:52,490 Good. 140 00:09:52,490 --> 00:09:53,760 Great. 141 00:09:53,760 --> 00:09:54,720 So what you guys under. 142 00:09:54,780 --> 00:09:55,390 So yes. 143 00:09:55,430 --> 00:09:56,390 You see here. 144 00:09:56,390 --> 00:10:00,140 So first of all I will ask Python to verify if I want to eat. 145 00:10:00,170 --> 00:10:03,260 If yes I want to eat I want Python to print. 146 00:10:03,260 --> 00:10:08,420 Let's go to the restaurant if I don't want to eat. 147 00:10:08,420 --> 00:10:11,270 I won't bite on to verify if I want a drink if I want to drink. 148 00:10:11,270 --> 00:10:12,570 I want Python to print. 149 00:10:12,590 --> 00:10:14,210 Let's have a drink. 150 00:10:14,210 --> 00:10:16,000 Otherwise I won't bite into print. 151 00:10:16,040 --> 00:10:16,950 I'm good. 152 00:10:17,000 --> 00:10:21,840 So if I run this up the first thing I'm gonna see is I'm good because both of those values are false. 153 00:10:21,980 --> 00:10:24,640 If let's say the value I want to eat is true 154 00:10:29,930 --> 00:10:33,500 right there so Python verifies I want to eat. 155 00:10:33,510 --> 00:10:33,990 It's true. 156 00:10:33,990 --> 00:10:35,160 So Python should return. 157 00:10:35,250 --> 00:10:36,600 Let's go to the restaurant. 158 00:10:36,600 --> 00:10:39,310 I run my app and yes that's what I see. 159 00:10:39,360 --> 00:10:42,710 If instead both of the values are true. 160 00:10:43,110 --> 00:10:50,370 So there's value in this value to the Apple step running here because I don't if I if I want to eat 161 00:10:50,580 --> 00:10:50,880 print. 162 00:10:50,880 --> 00:10:53,670 Let's go to the restaurant so python will print this. 163 00:10:53,670 --> 00:10:54,180 And that's it. 164 00:10:54,210 --> 00:10:55,560 The app stops here. 165 00:10:55,570 --> 00:11:01,050 Well it's gonna stop running here but if it's not truthful it's just the way I fight this. 166 00:11:01,080 --> 00:11:02,290 So as you can see it stops here. 167 00:11:02,460 --> 00:11:06,600 But if I want to eat is false. 168 00:11:06,720 --> 00:11:09,140 So in this case by will verify if I want to eat. 169 00:11:09,160 --> 00:11:10,020 No that's false. 170 00:11:10,020 --> 00:11:10,840 I don't want to eat. 171 00:11:10,980 --> 00:11:13,760 So I don't then we'll verify if I want to drink. 172 00:11:13,860 --> 00:11:16,600 And in this case it's is weird. 173 00:11:16,620 --> 00:11:17,740 So it's going to return. 174 00:11:17,760 --> 00:11:18,540 Let's have a drink. 175 00:11:18,600 --> 00:11:23,680 So if we run our app as you can see by then return let's have a drink. 176 00:11:23,700 --> 00:11:24,810 So those are the apps. 177 00:11:24,810 --> 00:11:29,030 Well those are the ways that you guys can use the if statement. 178 00:11:29,070 --> 00:11:33,120 Another thing that you can add to your if statement and that's the last thing that we are gonna talk 179 00:11:33,120 --> 00:11:39,960 about is the not so let's say for example I am using the if statement right here and I want to verify 180 00:11:40,020 --> 00:11:44,250 the reverse so let's say for example if I don't want to eat. 181 00:11:44,400 --> 00:11:47,230 In this case I will simply verify if not. 182 00:11:47,620 --> 00:11:50,820 So if I don't want to eat I want a python to return. 183 00:11:50,880 --> 00:11:53,130 Let's go to the restaurant which doesn't make sense. 184 00:11:53,130 --> 00:11:56,040 Once again it's just for the example. 185 00:11:56,040 --> 00:11:57,650 So let's change the example a bit. 186 00:11:57,840 --> 00:12:04,770 If I don't want to eat I want Python to return I'm good. 187 00:12:05,170 --> 00:12:06,720 Good. 188 00:12:06,730 --> 00:12:11,970 So in this case python will verify if I don't want to eat. 189 00:12:11,970 --> 00:12:16,590 So in this case if I not do so it's going to be the reverse instead of being false. 190 00:12:16,730 --> 00:12:18,610 It's gonna be like if it's true. 191 00:12:18,850 --> 00:12:20,650 So python will verify if it's true 192 00:12:23,890 --> 00:12:27,510 in this case let's write down true. 193 00:12:28,250 --> 00:12:33,040 So what Python will do Python will verify if it's true if it's not true by ton. 194 00:12:33,040 --> 00:12:38,560 Well if it's true it's gonna become false so the only thing that did not do it will simply change the 195 00:12:38,560 --> 00:12:39,070 value here. 196 00:12:39,070 --> 00:12:40,660 So instead of being true it's going to be false. 197 00:12:40,690 --> 00:12:45,210 So Python should return nothing but you can see Python return nothing. 198 00:12:45,450 --> 00:12:49,100 And if it's false false. 199 00:12:50,050 --> 00:12:55,870 And when the python returns I'm good because the only thing that the not will do bio do not value right 200 00:12:55,870 --> 00:12:56,310 here. 201 00:12:56,460 --> 00:12:59,370 I will simply verify if the reverse is true. 202 00:12:59,380 --> 00:13:01,150 So in this case is the reverse. 203 00:13:01,300 --> 00:13:03,380 Well if it's false here it's gonna become true. 204 00:13:03,400 --> 00:13:05,370 And if it's true it's become it becomes false. 205 00:13:07,060 --> 00:13:07,560 All right. 206 00:13:07,600 --> 00:13:15,700 So until now guys you understand the if statement and how it works if you guys still still have problems 207 00:13:15,700 --> 00:13:20,740 with this I suggest you to repeat this class to be able to understand that because once again the if 208 00:13:20,740 --> 00:13:26,830 statement is something that is very very huge in Python and practice it. 209 00:13:26,830 --> 00:13:31,930 So that's the best way for you guys to learn it so you can practice and make make some exercises you 210 00:13:31,930 --> 00:13:35,190 can make exercise about food about colors about anything you want. 211 00:13:35,260 --> 00:13:39,940 I practice it a little bit and you'll see it's not something that is hurt. 212 00:13:39,940 --> 00:13:41,400 It's just about practice. 213 00:13:41,500 --> 00:13:44,830 That's it for this class guys and see in our next class.