1 00:00:00,580 --> 00:00:00,910 Oh yes. 2 00:00:00,920 --> 00:00:04,510 And welcome back to another class of our course about Python. 3 00:00:05,150 --> 00:00:08,520 So until now we talked about a lot of very interesting things. 4 00:00:08,670 --> 00:00:15,470 And until now you were supposed to have a pretty much good knowledge of python and how it works. 5 00:00:15,480 --> 00:00:20,130 So we talked in our best class about the if statement and how exactly it works. 6 00:00:20,130 --> 00:00:27,120 We talked about the if or statement we talked about the if and statement and basically everything what's 7 00:00:27,180 --> 00:00:28,240 around the if statement. 8 00:00:28,580 --> 00:00:32,690 And we also saw that the if statement works with the boolean. 9 00:00:33,120 --> 00:00:42,150 So usually you need a true or a false to be able to run an if statement which is true in the majority 10 00:00:42,150 --> 00:00:50,830 of cases but you don't really need the statement in itself to be able to run an IF function. 11 00:00:50,910 --> 00:00:55,800 Let me explain myself so you can compare it let's say for example when you compare a number to another 12 00:00:55,800 --> 00:00:57,130 number. 13 00:00:57,720 --> 00:01:00,160 Normally you will have a true or false value. 14 00:01:00,180 --> 00:01:04,470 So for example if you compare one with one well one equals to one. 15 00:01:04,540 --> 00:01:07,160 And in this case you have your if statement. 16 00:01:07,170 --> 00:01:16,720 So this statement means it's true because 1 equals 2 1 So this is the same thing for for our well for 17 00:01:16,720 --> 00:01:18,470 our what we will do today. 18 00:01:18,490 --> 00:01:25,510 So my goal today is really to present you guys how exactly we can work with the if statement without 19 00:01:25,510 --> 00:01:30,650 necessarily having a true or false values or boolean values. 20 00:01:31,290 --> 00:01:33,040 So let's try this out. 21 00:01:33,080 --> 00:01:33,970 So the first thing. 22 00:01:34,000 --> 00:01:42,380 So we'll we'll do some of the also two basic exercises with variables and then after that we'll go and 23 00:01:42,380 --> 00:01:44,290 work with some more advanced data. 24 00:01:44,570 --> 00:01:47,150 So let's start the first thing that I will do. 25 00:01:47,210 --> 00:01:50,060 We can just watch for now. 26 00:01:50,060 --> 00:01:55,160 I'll have two variables so I'll have verbal number one which will be equal to one and viable number 27 00:01:55,160 --> 00:01:58,170 two which will be equal to five. 28 00:01:59,900 --> 00:02:01,250 I'll write down my if statement. 29 00:02:01,260 --> 00:02:12,850 So in this case if variable number one is equal to variable number five a variable number two. 30 00:02:12,860 --> 00:02:16,910 Sorry I want to print. 31 00:02:17,960 --> 00:02:18,320 Yes 32 00:02:20,840 --> 00:02:21,440 otherwise 33 00:02:24,560 --> 00:02:25,490 I want to print. 34 00:02:25,520 --> 00:02:26,360 No. 35 00:02:26,390 --> 00:02:28,490 So in this case print. 36 00:02:29,040 --> 00:02:30,210 No. 37 00:02:30,410 --> 00:02:33,180 If I run the app so just over two points. 38 00:02:33,350 --> 00:02:36,920 If I run my app as you can see the answer will be no. 39 00:02:37,310 --> 00:02:37,610 Why. 40 00:02:37,610 --> 00:02:41,050 Because variable number one is not equal to variable number two. 41 00:02:41,120 --> 00:02:44,200 And in this case if for example I write down five. 42 00:02:44,630 --> 00:02:47,420 So if I won my app it's gonna be yes. 43 00:02:47,420 --> 00:02:53,210 So as you can see I don't necessarily have the true or false statement and nowhere no statements are 44 00:02:53,390 --> 00:03:00,590 the true or false data nor where there is stored in any variable but instead I have let's say numbers. 45 00:03:00,590 --> 00:03:06,830 So I compare one number to another number and because they are you one not the first number is equal 46 00:03:06,830 --> 00:03:08,110 to the same number. 47 00:03:08,120 --> 00:03:10,130 This means that it's true. 48 00:03:10,130 --> 00:03:11,210 So this value is true. 49 00:03:11,210 --> 00:03:14,570 So this theoretically equals 2 true. 50 00:03:14,900 --> 00:03:17,350 And because of that python will print. 51 00:03:17,510 --> 00:03:23,300 Yes I can do it more eventually for example I can even have let's say three variables or in this case 52 00:03:23,540 --> 00:03:25,880 three variables and let's say all right. 53 00:03:25,940 --> 00:03:34,990 Equal to to I can even print something like this equal to variable number three and I can run my app 54 00:03:36,000 --> 00:03:37,420 and as you can see the value will be no. 55 00:03:37,510 --> 00:03:37,780 Why. 56 00:03:37,780 --> 00:03:43,150 Because Bible number one is equal to Bible number two but is not equal to viable number three. 57 00:03:43,150 --> 00:03:47,940 So what I can use is another statement which is not equal to verbal. 58 00:03:47,950 --> 00:03:49,070 Number three. 59 00:03:49,090 --> 00:03:51,340 So if I run my app it's gonna be yes. 60 00:03:51,340 --> 00:03:51,610 Why. 61 00:03:51,610 --> 00:03:58,470 Because Bible number one is equal to Bible number two but not equal to verbal number three so if you 62 00:03:58,470 --> 00:04:03,510 want to write equal it's gonna be two equal signs if you're on the right don't not equal it's gonna 63 00:04:03,510 --> 00:04:06,730 be an exclamation mark and an equal sign. 64 00:04:06,740 --> 00:04:07,060 All right. 65 00:04:07,200 --> 00:04:10,620 So right now you get the point of all this. 66 00:04:11,400 --> 00:04:13,530 Let's try something else. 67 00:04:13,570 --> 00:04:22,080 Let's say for example here I'll have five and six instead of equal what I can do is I can write greater. 68 00:04:22,170 --> 00:04:27,750 So let's say for example Bible number one is greater than Bible number two. 69 00:04:27,900 --> 00:04:28,670 And two points. 70 00:04:28,860 --> 00:04:29,250 Once a year. 71 00:04:29,280 --> 00:04:35,200 If I run my app as you can see Bible number one is not greater than variable number two. 72 00:04:35,200 --> 00:04:37,390 So in this case the answer will be no. 73 00:04:37,600 --> 00:04:44,420 But what I can do also I can say for example equal or greater or equal. 74 00:04:44,600 --> 00:04:51,720 So in this case if I run it it's going to be no but if it's five it's gonna be yes because it's equal. 75 00:04:51,730 --> 00:04:54,520 So in this case I would ask if it's greater or equal. 76 00:04:54,520 --> 00:04:55,350 Well it's equal. 77 00:04:55,360 --> 00:05:02,900 So devout the answer will be yes you can do this for greater for equal for greater or equal for smaller 78 00:05:02,900 --> 00:05:04,940 equal can do this for many many. 79 00:05:04,940 --> 00:05:07,110 Well there are many comparisons that exist. 80 00:05:07,310 --> 00:05:15,050 But the most popular ones are equal not equal greater smaller greater or equal smaller or equal. 81 00:05:15,950 --> 00:05:16,220 All right. 82 00:05:16,250 --> 00:05:25,600 So right now that you understand what exactly are is the comparison part in the if statement I propose 83 00:05:25,600 --> 00:05:31,100 we guys to make two basic apps so you'll be able to practice and understand it a little bit more. 84 00:05:31,180 --> 00:05:33,440 So let's jump in. 85 00:05:33,520 --> 00:05:36,270 So the first thing I'll ask you guys to do is open up your wallet. 86 00:05:36,340 --> 00:05:42,460 You already on so on Europe your text editor and what you will do is create four variables. 87 00:05:42,460 --> 00:05:46,850 So we'll have one and we'll use colors so we'll use string. 88 00:05:46,870 --> 00:05:49,020 You can use colors or any other type of string. 89 00:05:49,050 --> 00:05:50,320 Doesn't matter. 90 00:05:50,320 --> 00:05:51,730 So we have 4 1 4 2 91 00:05:57,220 --> 00:05:57,660 right. 92 00:05:58,500 --> 00:06:00,450 So we have everything what we need that we need 93 00:06:04,510 --> 00:06:07,890 after that you simply add the colors that you want to add. 94 00:06:08,160 --> 00:06:12,140 So in my case it's gonna be blue red black and yellow. 95 00:06:14,550 --> 00:06:14,850 Great 96 00:06:21,360 --> 00:06:21,980 I have what I need. 97 00:06:22,470 --> 00:06:23,810 So I will do right now. 98 00:06:23,850 --> 00:06:27,990 Also my goal right now is simply to show you that you can compare strings together. 99 00:06:28,590 --> 00:06:34,110 So five seconds ago we compared numbers together but right now we'll compare strings together. 100 00:06:34,110 --> 00:06:40,950 So for example if we write down our if available once again a function sorry. 101 00:06:40,950 --> 00:06:48,680 We have our variable number one which is for example equal to level number two in the case that it's 102 00:06:48,690 --> 00:06:50,250 true. 103 00:06:50,490 --> 00:06:53,180 What we'll do we want Python to return. 104 00:06:53,190 --> 00:06:53,490 Print. 105 00:06:54,450 --> 00:06:54,960 Yes. 106 00:06:54,980 --> 00:07:00,090 It's the same color. 107 00:07:00,300 --> 00:07:00,570 Great 108 00:07:03,950 --> 00:07:07,370 so we run our app and we have nothing because it's not the same. 109 00:07:07,370 --> 00:07:09,670 So what will be our same condition. 110 00:07:09,800 --> 00:07:13,310 Else if it's not true. 111 00:07:13,320 --> 00:07:15,680 Once Python to print. 112 00:07:15,700 --> 00:07:23,620 No no it's not true enough or yet very important. 113 00:07:23,670 --> 00:07:27,900 You're two points when it's all done simply run your app. 114 00:07:28,010 --> 00:07:31,240 So as you can see the answer is no it's not true. 115 00:07:31,250 --> 00:07:36,000 Because Bible number one is not equal to Bible number two if for example. 116 00:07:36,130 --> 00:07:38,000 Here we have red. 117 00:07:38,020 --> 00:07:39,710 So red is equal to red. 118 00:07:39,730 --> 00:07:40,500 We run our app. 119 00:07:40,900 --> 00:07:42,660 Yes it's the same color. 120 00:07:43,210 --> 00:07:49,630 So we can if it is the same thing it's going to tell you this but let's say for example we have red 121 00:07:49,630 --> 00:07:52,420 with a capital letter and red with the small letter. 122 00:07:52,420 --> 00:07:53,650 It's not going to work. 123 00:07:53,650 --> 00:07:53,890 Why. 124 00:07:53,890 --> 00:07:56,840 Because Python respects kept the letters. 125 00:07:56,890 --> 00:08:04,060 So if you have two words but the letters one it's in the capital the other is not it's not gonna work. 126 00:08:04,080 --> 00:08:08,890 So very important you need the exact same thing if you want it to work. 127 00:08:08,910 --> 00:08:09,170 All right. 128 00:08:09,190 --> 00:08:14,400 So right now you get the point that you can compare strings together you can compare numbers together 129 00:08:14,400 --> 00:08:19,360 you can compare boolean together you can compare absolutely everything together but you can't compare 130 00:08:19,370 --> 00:08:25,500 string with numbers or numbers with that for example Boolean if for example you want to compare numbers 131 00:08:25,500 --> 00:08:31,980 with strings and you need to transform your string into a number before being able to do it and you 132 00:08:31,980 --> 00:08:33,000 have some functions do it. 133 00:08:33,590 --> 00:08:34,710 All right we will. 134 00:08:34,740 --> 00:08:38,260 So let's create another small app. 135 00:08:38,910 --> 00:08:44,700 This time it's going to give him the app will be a bit more complex since I want you guys to practice 136 00:08:44,700 --> 00:08:49,710 a bit more but that in this app what we'll do principally is very simple. 137 00:08:49,710 --> 00:08:55,680 Our goal is to find out who is the richest person between the three different persons. 138 00:08:56,820 --> 00:09:02,970 So what exactly we'll have to do right now the first thing we'll need to find out the name of each person. 139 00:09:02,970 --> 00:09:09,420 So we'll ask users to enter their names and enter how much money they have. 140 00:09:09,480 --> 00:09:11,010 So let's write it down. 141 00:09:11,490 --> 00:09:15,280 So we have our first variable which will be a person's name. 142 00:09:15,330 --> 00:09:18,920 So we have divided it looks like this equal input. 143 00:09:19,200 --> 00:09:26,640 So we have our input and we'll ask our user to do is what is your name. 144 00:09:26,640 --> 00:09:34,450 So right here the user will enter his or her name from now the next thing that we want to know from 145 00:09:34,450 --> 00:09:37,080 this user is how much money do you have. 146 00:09:37,120 --> 00:09:45,670 So we'll treat another variable that will name person's wallet the state's purse wallet and we'll write 147 00:09:45,670 --> 00:09:55,480 down input and ask the person how much money do you have. 148 00:09:58,620 --> 00:09:59,720 Right. 149 00:09:59,950 --> 00:10:06,430 So the better the person will answer us with his or her name and the money that that this person as 150 00:10:07,240 --> 00:10:08,180 you can. 151 00:10:08,180 --> 00:10:13,960 Right now what we need to do is the exact same thing for the two next persons because we'll have three 152 00:10:14,170 --> 00:10:20,020 different persons so you can simply copy everything and past it and instead of having person number 153 00:10:20,020 --> 00:10:22,080 one we'll have person number two. 154 00:10:22,360 --> 00:10:23,370 Great. 155 00:10:23,380 --> 00:10:31,290 So we do this for person number two and person number three as well. 156 00:10:31,400 --> 00:10:31,700 All right. 157 00:10:31,790 --> 00:10:35,000 So until now you have everything you need to be able to continue. 158 00:10:36,320 --> 00:10:41,930 So if person number one number two and number two write down that we have our basic database. 159 00:10:41,930 --> 00:10:44,300 It's time for us to create our app. 160 00:10:45,050 --> 00:10:51,020 So once again we'll use the if function in this app to be able to run it. 161 00:10:51,020 --> 00:10:54,710 So what we will ask well will ask Python to do right now. 162 00:10:54,710 --> 00:10:55,760 Very simple. 163 00:10:55,760 --> 00:11:01,430 We want to know what the name of the person end if the person number one has more money than the person 164 00:11:01,430 --> 00:11:01,880 number two. 165 00:11:02,120 --> 00:11:06,690 If yes we want to verify if Person number one has more money than person number three. 166 00:11:06,890 --> 00:11:12,530 If those two statements are respected we'll simply return person number one is the richest. 167 00:11:13,610 --> 00:11:16,140 So very very simple as you can see the app is simple. 168 00:11:16,280 --> 00:11:17,870 Right now it's time to create it. 169 00:11:18,440 --> 00:11:23,960 So we'll have our if statement right here and the first thing that will need to enter right now is we 170 00:11:23,960 --> 00:11:31,510 need to convert our strings into numbers so as I explained before you can't work with strings and numbers 171 00:11:31,600 --> 00:11:35,470 at the same time because Python can compare strings with numbers. 172 00:11:35,560 --> 00:11:38,780 So very important to convert to convert it first. 173 00:11:38,800 --> 00:11:45,790 So how do we convert strings to numbers with the float functions that don't float open up your parentheses 174 00:11:47,080 --> 00:11:55,240 and you copy this variable right here. 175 00:11:55,510 --> 00:12:05,410 So if person number one while it equal in this case to Person number two wallet now for you have to 176 00:12:05,410 --> 00:12:09,910 write down your float function because without it nothing will work. 177 00:12:10,000 --> 00:12:12,430 You'll have errors. 178 00:12:12,430 --> 00:12:12,660 So. 179 00:12:12,670 --> 00:12:12,930 All right. 180 00:12:12,940 --> 00:12:16,790 We have float person number one wallet greater than Person number two. 181 00:12:16,860 --> 00:12:24,580 Well so this is the first part of the function we verify if it's true then we want to verify if the 182 00:12:24,580 --> 00:12:28,170 person number one has more money than the person number tweet as well. 183 00:12:28,210 --> 00:12:29,890 So we'll use the end function here. 184 00:12:29,890 --> 00:12:38,260 We'll use if and and we'll write down our float to be able to work with the numbers. 185 00:12:38,530 --> 00:12:48,630 So person number one wallet is greater than 186 00:12:51,250 --> 00:12:57,590 Person number two well all right so we have everything we need. 187 00:12:57,860 --> 00:13:01,650 We write down our two points and we jump. 188 00:13:01,700 --> 00:13:02,860 So next question. 189 00:13:02,910 --> 00:13:08,150 Next thing that we need to do right now that we have our first function ready is our output right. 190 00:13:08,150 --> 00:13:09,090 Our output. 191 00:13:09,800 --> 00:13:12,590 So very simple what one python to print right now. 192 00:13:12,590 --> 00:13:13,210 So very simple. 193 00:13:13,220 --> 00:13:19,060 We print person number one name. 194 00:13:19,100 --> 00:13:24,230 So we need the name of the person number one plus is the richest. 195 00:13:24,230 --> 00:13:27,410 So is the richest. 196 00:13:27,470 --> 00:13:30,440 So we have our inputs right here. 197 00:13:30,650 --> 00:13:33,360 We have our database right here so everyone enters his name. 198 00:13:33,380 --> 00:13:34,710 And how much money he has. 199 00:13:34,880 --> 00:13:36,020 The calculation right here. 200 00:13:36,030 --> 00:13:40,640 So person number one wallet greater than Person number two same thing for a person number three 201 00:13:44,070 --> 00:13:51,420 and then we print the name of person number one is the richest if it's true if it's false if it doesn't 202 00:13:51,420 --> 00:13:55,090 work what we need to do right now is very simple. 203 00:13:55,500 --> 00:14:01,770 So we verify if it's number two the person number two is the richest. 204 00:14:02,160 --> 00:14:08,040 So in this case we'll use the Elif function once again it's an if function that is integrated in another 205 00:14:08,190 --> 00:14:10,550 function. 206 00:14:10,740 --> 00:14:13,650 So we do the exact same thing instead of free writing. 207 00:14:13,650 --> 00:14:22,380 Everything can simply copy it and post it here then the next thing that you guys need to do is changing 208 00:14:22,500 --> 00:14:23,470 the name of people. 209 00:14:23,470 --> 00:14:28,220 So here we'll have Person number two is richer than person number one. 210 00:14:28,230 --> 00:14:28,920 Same thing here. 211 00:14:28,920 --> 00:14:35,450 Person number two in number three and in the name not forget the right person number two as well 212 00:14:38,510 --> 00:14:45,570 and finally you copy and paste everything to be able to do the exact same thing for person number two 213 00:14:58,860 --> 00:15:02,610 when we have all this what we can do now we can run up. 214 00:15:03,000 --> 00:15:08,880 So we have absolutely everything we have our condition so our logical test for Person 1 2 and 3 and 215 00:15:08,870 --> 00:15:11,140 we can run our up to see what it looks like. 216 00:15:11,160 --> 00:15:12,060 So what is your name. 217 00:15:12,330 --> 00:15:17,990 In this case name will say Jack how much money Jack has one hundred dollars. 218 00:15:18,120 --> 00:15:21,020 What is your name. 219 00:15:21,070 --> 00:15:21,590 I don't know. 220 00:15:21,640 --> 00:15:24,020 Meaning how much money Mina has. 221 00:15:24,080 --> 00:15:25,310 Fifty dollars. 222 00:15:25,380 --> 00:15:27,310 And finally what is your name. 223 00:15:27,330 --> 00:15:29,630 So let's say John. 224 00:15:30,150 --> 00:15:31,410 How much money John has. 225 00:15:31,410 --> 00:15:32,940 Twenty five dollars. 226 00:15:32,940 --> 00:15:33,840 We run our app. 227 00:15:33,940 --> 00:15:35,130 Jack is the richest. 228 00:15:35,130 --> 00:15:35,900 Which makes sense. 229 00:15:37,020 --> 00:15:38,850 Let's change our inputs. 230 00:15:38,850 --> 00:15:40,440 In this case what's earning. 231 00:15:40,560 --> 00:15:42,030 Once again we'll say Jack 232 00:15:44,830 --> 00:15:46,240 how much money do we have Jack. 233 00:15:46,270 --> 00:15:47,500 Ten dollars. 234 00:15:47,640 --> 00:15:49,710 Mina how much money do you have. 235 00:15:49,720 --> 00:15:50,600 Fifty dollars. 236 00:15:51,310 --> 00:15:53,260 And finally what's your name. 237 00:15:53,260 --> 00:15:54,410 Let's say John. 238 00:15:54,520 --> 00:15:56,220 How much money do you have John. 239 00:15:56,270 --> 00:15:58,450 Fifteen let's say fifteen dollars. 240 00:15:58,450 --> 00:15:59,250 We run the app. 241 00:15:59,290 --> 00:16:03,990 Mina is the richest as you can see Isaac is very very simple. 242 00:16:04,040 --> 00:16:08,750 The app works perfectly we can find who is the richest person. 243 00:16:08,760 --> 00:16:15,820 So until now you know how you can use the if statement the if statement is really for decision making. 244 00:16:15,890 --> 00:16:22,100 And right now you can see that you don't necessarily need the Boolean value the true and the false rate 245 00:16:22,110 --> 00:16:26,090 in somewhere or stored somewhere in a variable. 246 00:16:26,390 --> 00:16:33,970 You can just compare a you can compare a string with a string and expect to have a true or false value 247 00:16:33,980 --> 00:16:39,320 so let's say for example if two things are not the same or it doesn't respect the comparison. 248 00:16:39,320 --> 00:16:42,040 Well this means it's not true. 249 00:16:42,290 --> 00:16:46,580 And if it respects it well this means it's true. 250 00:16:46,580 --> 00:16:50,140 So let's say a number is greater than another number. 251 00:16:50,150 --> 00:16:54,170 Well this means it respects the comparison of this number is greater than this number. 252 00:16:54,170 --> 00:16:55,220 So in this case it's true. 253 00:16:56,660 --> 00:17:03,140 So I hope you guys understand right now that you can work with the if statement this week and this will 254 00:17:03,140 --> 00:17:08,840 be very very useful for you guys in the future when you will become more advanced in this programming 255 00:17:08,840 --> 00:17:09,440 language. 256 00:17:09,470 --> 00:17:10,400 So that's it for this class. 257 00:17:10,430 --> 00:17:12,680 Guys see you all in our next class.