1 00:00:00,640 --> 00:00:05,610 Hello guys and welcome back to another class of our course about Python. 2 00:00:05,640 --> 00:00:10,290 So until now we saw many many things and we talked about the if statement. 3 00:00:10,620 --> 00:00:13,930 And right now it's time to put everything in practice. 4 00:00:14,100 --> 00:00:18,750 So what I want to do in this class is really practicing the if statement that we learned before it as 5 00:00:18,750 --> 00:00:25,030 well as the functions and the putting everything together so very simple. 6 00:00:25,030 --> 00:00:31,540 What I propose you guys doing today is a small basic app that will be a conversation between a user 7 00:00:32,020 --> 00:00:33,010 and a person. 8 00:00:33,400 --> 00:00:36,140 So in this case what exactly will the app look like. 9 00:00:36,160 --> 00:00:40,340 So the first thing we will do is we'll tell the rules to our users. 10 00:00:40,360 --> 00:00:45,000 So the rules will simply be answering each question by yes or no. 11 00:00:45,010 --> 00:00:49,110 So if the user says yes to this I will go to the next question. 12 00:00:49,120 --> 00:00:55,150 If the user says no we'll simply print stop then ask the first question the same question. 13 00:00:55,150 --> 00:00:56,770 The third question and the fourth question. 14 00:00:56,830 --> 00:01:00,690 Well the third question because it stops at trick questions. 15 00:01:00,730 --> 00:01:02,920 So basically this is the goal of our app. 16 00:01:03,850 --> 00:01:05,020 So let's start. 17 00:01:05,350 --> 00:01:06,130 So very basically. 18 00:01:06,130 --> 00:01:11,820 But what exactly will start in this case will put everything inside of a phone it of a function. 19 00:01:11,830 --> 00:01:14,700 Because if we don't do this it simply will not work. 20 00:01:15,480 --> 00:01:15,770 All right. 21 00:01:16,240 --> 00:01:18,160 So how exactly this will work. 22 00:01:18,190 --> 00:01:26,260 Well write down firstly def so def is a way to tape them to tell Python that we start our function here. 23 00:01:26,440 --> 00:01:28,870 The name of our function will be question. 24 00:01:29,050 --> 00:01:31,480 So simply name the question. 25 00:01:31,630 --> 00:01:33,850 You write down two points. 26 00:01:33,850 --> 00:01:34,200 All right. 27 00:01:35,050 --> 00:01:38,360 So first thing we'll write down rules. 28 00:01:38,380 --> 00:01:44,770 So the first variable that we will have inside of our of our function will be the variable rules. 29 00:01:45,160 --> 00:01:48,870 In this case we'll ask our user. 30 00:01:49,180 --> 00:01:50,830 You need to answer every question. 31 00:01:50,830 --> 00:01:54,160 So we'll write it down. 32 00:01:54,160 --> 00:01:57,340 You need to answer 33 00:02:02,360 --> 00:02:08,300 every question by yes or no. 34 00:02:08,300 --> 00:02:16,660 Do you under stand. 35 00:02:16,920 --> 00:02:20,100 So you're our user will give us an answer by yes or no. 36 00:02:21,270 --> 00:02:21,570 All right. 37 00:02:22,320 --> 00:02:26,260 So once the user read this he will answer. 38 00:02:26,820 --> 00:02:31,010 So we'll start with our if statement. 39 00:02:31,080 --> 00:02:37,160 So if the variable rules is not equal to yes. 40 00:02:37,170 --> 00:02:38,760 So if it's equal to no. 41 00:02:39,840 --> 00:02:45,130 So if the variable rules is equal to no we want to return stop. 42 00:02:45,360 --> 00:02:51,550 So in this case we'll ask Python to print stuff or will print and we'll ask him to print trade. 43 00:02:51,570 --> 00:02:52,700 So let's say try again 44 00:02:56,470 --> 00:02:56,870 great. 45 00:02:57,230 --> 00:03:00,790 So you can see yes right now our first rule is very simple. 46 00:03:01,040 --> 00:03:04,670 If we if our user returns. 47 00:03:04,700 --> 00:03:06,560 Yes we go to the next question. 48 00:03:06,620 --> 00:03:09,300 If no the the apple stop here. 49 00:03:09,320 --> 00:03:10,670 Well our function will stop here. 50 00:03:10,670 --> 00:03:15,680 This is why we use the return statement in this case will stop our function right here. 51 00:03:15,860 --> 00:03:21,110 If in the case that this is not respected great. 52 00:03:21,140 --> 00:03:25,250 So once this is done it's time to write our second question. 53 00:03:25,250 --> 00:03:27,450 In this case it will be else. 54 00:03:27,470 --> 00:03:31,070 So what's happening in the case that this is not respected. 55 00:03:31,070 --> 00:03:32,780 Well this is respected. 56 00:03:32,780 --> 00:03:34,970 So we'll print next question 57 00:03:41,610 --> 00:03:41,910 great 58 00:03:46,360 --> 00:03:49,510 so we have everything right now. 59 00:03:49,510 --> 00:03:51,860 Next thing that we want to do is write down the first question. 60 00:03:51,880 --> 00:03:56,790 So once again we'll use a variable to write down the questions or in this case we'll have question 1. 61 00:03:56,800 --> 00:03:57,850 So quest 1 62 00:04:01,740 --> 00:04:03,910 and the question 1 will be very simple. 63 00:04:03,990 --> 00:04:05,040 We'll ask our user. 64 00:04:05,040 --> 00:04:05,910 Are you hungry. 65 00:04:07,410 --> 00:04:11,640 So once again we'll write down an input because we want an answer from him. 66 00:04:11,640 --> 00:04:13,740 Are you hungry 67 00:04:17,540 --> 00:04:19,720 and once again we'll have our if statement. 68 00:04:19,880 --> 00:04:23,600 So if the variable quest one 69 00:04:26,300 --> 00:04:30,150 is not equal to yes or is equal to no. 70 00:04:30,980 --> 00:04:32,900 We want to return. 71 00:04:32,900 --> 00:04:38,280 So we will give the answer to our user. 72 00:04:38,780 --> 00:04:42,020 Then let's go for a walk. 73 00:04:42,290 --> 00:04:42,950 In this case 74 00:04:50,520 --> 00:04:51,810 we'll tell this to our user 75 00:04:55,380 --> 00:05:03,380 so once again the question is if this variable right here is not equal to yes we want to return to our 76 00:05:03,380 --> 00:05:03,850 user. 77 00:05:03,920 --> 00:05:05,900 Then let's go for a walk and everything stops here. 78 00:05:05,900 --> 00:05:08,240 So the app will stop there. 79 00:05:08,240 --> 00:05:12,680 In the case that the answer is yes. 80 00:05:12,740 --> 00:05:14,150 So here is not yes. 81 00:05:14,270 --> 00:05:18,010 If the answer is no we return this in the case that the answer is yes. 82 00:05:18,090 --> 00:05:21,260 What we want to do well we simply go to the next question. 83 00:05:21,270 --> 00:05:23,200 So we print else. 84 00:05:23,460 --> 00:05:36,300 Next question. 85 00:05:36,580 --> 00:05:37,510 So what's the next thing. 86 00:05:37,750 --> 00:05:40,630 So right now we'll ask our user. 87 00:05:40,630 --> 00:05:42,840 Do you want to eat at a restaurant. 88 00:05:42,970 --> 00:05:50,590 Since our user is hungry we want to ask him if he wants to eat somewhere. 89 00:05:50,650 --> 00:05:59,870 So once again we'll store our variable right here So write down our input function and ask our user. 90 00:05:59,870 --> 00:06:10,780 Do you want to eat at the race. 91 00:06:11,060 --> 00:06:12,650 Great. 92 00:06:12,730 --> 00:06:16,500 So right now we have our second variable or our second question. 93 00:06:16,530 --> 00:06:22,310 Now it's time to ask the equity question so we'll write down the function if the if statements are. 94 00:06:22,650 --> 00:06:31,980 So ask our user if we'll tell our user if the answer to the question number two or the value of the 95 00:06:31,980 --> 00:06:36,540 variable quest to is not equal to yes 96 00:06:42,220 --> 00:06:45,820 we want Python to return. 97 00:06:47,440 --> 00:06:49,170 Come eat at my place. 98 00:06:56,820 --> 00:06:57,120 Great. 99 00:06:57,810 --> 00:07:04,920 So as you can see if this variable is not equal to yes we want Biden to return come eat at my place 100 00:07:05,460 --> 00:07:08,670 right now we have our two first questions. 101 00:07:08,670 --> 00:07:13,350 So the next thing with our if statement we're here we have what's happening in the case that this is 102 00:07:13,350 --> 00:07:19,560 true but in the case that this is false in the case that it's equal to yes what what exactly from Biden 103 00:07:19,950 --> 00:07:21,600 we want from him to print us. 104 00:07:21,600 --> 00:07:22,920 Next question. 105 00:07:22,920 --> 00:07:24,900 Once again the print next question is. 106 00:07:25,500 --> 00:07:35,110 Well we are not in the obligation to use it but once again it's it could be a good thing to use it right. 107 00:07:35,580 --> 00:07:37,620 We could work without the L statement here. 108 00:07:37,620 --> 00:07:42,210 We can just go with the if statement and then jump directly to the quest number two but once again we 109 00:07:42,210 --> 00:07:43,130 want that we'll have it. 110 00:07:43,530 --> 00:07:46,490 It's gonna be more let's say more cool. 111 00:07:46,520 --> 00:07:48,750 I find it more cool to write at them. 112 00:07:49,030 --> 00:07:49,260 Right. 113 00:07:49,800 --> 00:07:54,070 So next thing we go to the last question that we'll have. 114 00:07:54,310 --> 00:07:58,800 So once again we'll have our last question in this case what we want to do we'll do the exact same thing. 115 00:07:58,800 --> 00:08:01,930 We store our variable which will be quest treat. 116 00:08:02,010 --> 00:08:05,550 So question number three and in this case the last question will be do you. 117 00:08:05,570 --> 00:08:09,800 What do you want to eat a pizza to input once again. 118 00:08:09,800 --> 00:08:13,820 And we ask our user do you want to eat a pizza 119 00:08:20,950 --> 00:08:25,800 so in this case if our user 120 00:08:29,250 --> 00:08:33,980 tells us that he wants to eat it he wants to eat it pizza. 121 00:08:34,070 --> 00:08:39,830 Tell him let's go eat a pizza in the case that he tells us that he don't want to eat a pizza we'll tell 122 00:08:39,830 --> 00:08:41,940 him let's go eat a burger. 123 00:08:42,610 --> 00:08:44,650 So sorry not no. 124 00:08:44,710 --> 00:08:47,050 Yes. 125 00:08:47,410 --> 00:08:47,680 All right. 126 00:08:47,690 --> 00:08:55,950 So in the case that our user tell us no or the answer is not equal to yes we will return. 127 00:08:56,540 --> 00:08:58,010 Let's go eat a burger then 128 00:09:04,170 --> 00:09:08,970 go eat a burger then great. 129 00:09:09,720 --> 00:09:15,390 And in the case that the answer is yes we will return fancy and print. 130 00:09:15,390 --> 00:09:29,370 Let us go at the let's go eat pizza. 131 00:09:29,400 --> 00:09:33,130 So right now we have absolutely everything that we need to be able to run our app. 132 00:09:33,150 --> 00:09:35,820 So let me just summarize everything that we just wrote. 133 00:09:36,090 --> 00:09:40,190 So once again we started with Def def means the opening of a function. 134 00:09:40,200 --> 00:09:47,520 So we write down our function the name of the function which has questions and what is inside of our 135 00:09:47,520 --> 00:09:47,980 function. 136 00:09:48,000 --> 00:09:48,600 Very simple. 137 00:09:48,600 --> 00:09:50,340 We have the rules so input. 138 00:09:50,340 --> 00:09:55,270 You need to answer every question by yes or no the first. 139 00:09:55,300 --> 00:09:58,670 So right now we have our variable here rules. 140 00:09:58,690 --> 00:10:05,830 So if the variable rules is equal to yes is not equal to yes sorry we return try again if it's equal 141 00:10:05,830 --> 00:10:09,220 to yes we return next question and we go to the next question. 142 00:10:09,220 --> 00:10:12,560 So in this case next question will be are you hungry. 143 00:10:12,610 --> 00:10:14,530 If are you hungry. 144 00:10:14,530 --> 00:10:17,860 Is not equal to yes we return then let's go for a walk. 145 00:10:17,920 --> 00:10:19,960 If it's equal to yes we return. 146 00:10:20,020 --> 00:10:25,700 Next question and we do the same thing for question number two in question number three so let's run 147 00:10:25,970 --> 00:10:29,310 up and see what it looks like. 148 00:10:29,320 --> 00:10:31,860 So as you can see if we just click it doesn't work. 149 00:10:31,860 --> 00:10:35,750 So the way that we have to run our app is very simple we write down a question right here. 150 00:10:35,980 --> 00:10:40,180 So we write down the name of our function there. 151 00:10:40,560 --> 00:10:42,900 We run our up once again. 152 00:10:42,900 --> 00:10:43,780 Let's do this. 153 00:10:43,800 --> 00:10:48,060 So first question you need to answer every question by yes or no do you understand. 154 00:10:48,060 --> 00:10:49,940 So let's say we write down no. 155 00:10:50,170 --> 00:10:50,760 As you can see. 156 00:10:50,790 --> 00:10:52,840 Try again and it stops. 157 00:10:53,040 --> 00:10:57,240 If we run our app and says and say yes. 158 00:10:57,240 --> 00:10:58,050 Next question. 159 00:10:58,080 --> 00:11:00,020 Are you hungry. 160 00:11:00,030 --> 00:11:02,940 So in this case yes I am. 161 00:11:02,940 --> 00:11:05,100 Next question Do you want to eat at a restaurant. 162 00:11:05,100 --> 00:11:07,070 Let's say I write the note. 163 00:11:07,080 --> 00:11:08,370 Come eat at my place. 164 00:11:08,430 --> 00:11:10,240 And this is where the app stops. 165 00:11:10,260 --> 00:11:17,760 So once again you can write to points everywhere just to make it more beautiful and more presentable. 166 00:11:18,650 --> 00:11:21,930 But besides of that you see guys how all this works. 167 00:11:21,950 --> 00:11:23,720 So it's very very simple. 168 00:11:23,720 --> 00:11:27,890 So we run the app another time just to be sure at 100 percent. 169 00:11:27,980 --> 00:11:29,120 Everything works perfectly. 170 00:11:29,150 --> 00:11:30,530 So let's run the app. 171 00:11:31,310 --> 00:11:34,790 So you need to answer every questions we understand. 172 00:11:34,790 --> 00:11:36,410 Yes I understand. 173 00:11:36,410 --> 00:11:37,080 Are you hungry. 174 00:11:37,450 --> 00:11:39,720 So in this case let's say yes. 175 00:11:39,720 --> 00:11:41,120 Do you want to eat at a restaurant. 176 00:11:41,570 --> 00:11:42,980 Yes. 177 00:11:42,980 --> 00:11:44,420 Do you want to eat a pizza. 178 00:11:44,420 --> 00:11:44,800 Let's say. 179 00:11:44,850 --> 00:11:47,750 No let's go eat a burger then. 180 00:11:47,790 --> 00:11:50,720 So as you can see every time that I answer yes it goes. 181 00:11:50,740 --> 00:11:51,350 Next question. 182 00:11:51,380 --> 00:11:53,930 If I answer No everything stops here. 183 00:11:53,960 --> 00:11:58,160 So this is the goal of this app once again we just ask questions to our users. 184 00:11:59,180 --> 00:12:01,150 And as you can see it's something very very basic. 185 00:12:01,160 --> 00:12:04,550 Once again it puts everything that you guys just learned into practice. 186 00:12:04,580 --> 00:12:11,270 So I hope you guys right now understand much much better the if statement and how to use it you understand 187 00:12:11,270 --> 00:12:15,550 functions and everything because it's a very very important part of Python. 188 00:12:15,570 --> 00:12:21,050 So right now wrote a very simple code but you'll see the more will advance in the course the more you'll 189 00:12:21,680 --> 00:12:23,350 learn things so you'll need to remember. 190 00:12:23,390 --> 00:12:24,080 Absolutely. 191 00:12:24,080 --> 00:12:25,970 Well you'll need to remember everything. 192 00:12:26,480 --> 00:12:31,610 If you want to be good in programming so I'll suggest you to practice with me every time that we do 193 00:12:31,610 --> 00:12:33,280 small exercises like this. 194 00:12:33,280 --> 00:12:34,430 So that's it for the slides guys. 195 00:12:34,440 --> 00:12:36,680 And see in our next class.