20 Beginner Python Projects

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Improve your Python skills by building 20 projects Tommy taco has created many popular Python courses on our channel and now he will teach you how to build these beginner projects Hey guys in this video, we're gonna build 20 different Python projects So this is a list of all the projects that we're gonna build in this video So we're gonna build a lot of projects like a dice rolling simulator a quiz program an email slicer a binary search program an image Recycler and more as you can see on this list and if you like more tutorials like this Please don't forget to check out my channel at code with Tommy where I teach more on Python and web development in general So without wasting any time, let's get straight into this video In this tutorial I'm going to show you how to send an email with Python now, this is not a new concept There are various ways of doing this but with the recent update with Gmail the security has been changed So we have to go through some more security process before we are able to send a meal with Python But in this tutorial, I'm going to go through every single thing step by step on what we are going to do So let's quickly go to the steps in a comment So this is literally all we need to do but these are just the most crucial step number one and two Then once we have the password we will be able to come in here and then actually code what we need to send the mail So let's go over to Chrome and right here. I'm on my account my Google account So what you want to do is to come into security And a security so if I scroll down a little bit You see Two factor authentication. So in this two-factor authentication, I already have it on but what you want to do is to actually click On that if you have it off, then it's going to take you through some self-explanatory process It's going to ask for a number or something else that you can use to you know, back up your account Well, then what you do all of that that step is actually done What you need to do then is to come into this app password So what you can just do is either go into your URL and type slash app password Or you can just come here and click it directly so anyone wants to do is fine He's going to ask you to log in again. So we're just going to log in back And now that we log in as you can see I already have some password created that I used Sometime last year Now what we want to do is to actually select app and in this select app, we're not using any of these Options what we want to click on is this other and right here we can just say Python for Python and then we're going to Generate a code. So it's going to give us a code and what we want to do is to actually copy all of that code Because it's not going to show that code to us again. So want to copy it then click on done So once you have that code copied, as you can see, it's it's created on this time But it hasn't said when we last used it because we haven't used that particular password But once you have that done, that is good Those two processes are already done The next thing we want to do is to actually go into our file or go into our program and code this So what we're going to do now is to come back in here and The first thing we want to do is to import email. So save from email the message Import email message So this email is pre-installed is Python. So when you stop Python on your computer, this email should be There. So once we have that imported, let me actually go through what we're going to do So we're going to have a variable that is going to have the email sender So this is the email that you're sending from, which is the email that we generated a password for Then you are going to input the password that we generated. Now, this is not your email password This is the password that we generated. Then we're going to input the receiver So the person that is receiving this email, and once we've done that, we're going to specify the subject, the body And then we're going to create an instance of this email and actually send the email So next thing we want to do is to just have some variables so we can say email sender And the email sender has to be code with Tommy at gmail.com and email password So for this password, I'm actually not going to show the password I copied just for security reasons So right here, I have this app to file and I have the password stored in there So what I'm going to do is I'm going to show the password that I copied just for security reasons And I have the password stored in there. So what I'm just going to do is to actually import the password from that app to file So I'm going to say from up to the p y import password So I have that I have a variable in the name password. So that's what it's going to do So what we need to do is actually remove this dot p y, we just need to say from up to because they already knows is a Python file Import password. So now that we have that password, I'm just going to say password. And once we have that done, that is saved it So the email password is not the password that I created. So for you just the way we wrote the password here, you just need to write it there Or from a better security, you can just create an environment variable and store the password there instead So the next thing we want to do is to specify the email receiver So the person that is receiving this email, let's leave that blank for now, we're going to come back to do that. And then this next thing we want to do is to have the subject So we're going to say subject equals to Don't forget to subscribe And we're going to have the body so this is the main body of the email that means this is what the user is going to read So we want to have it like this with three quotes. Once we have that we're just going to write wherever I want to say you say When you watch a video, Is it subscribe? So once we have that the body is set, the next thing we want to do is to actually create an instance of this email message library or package that we Imported. So what we're going to do to create that we can see EM equals email message. So an instance has been created, then we're going to say EM From Is equals to email sender. So this is saying the person was sending from and then EM To Is equals to email receiver And then EM subject Is equals to the subject And then we're going to specify the body but we're going to do that a little bit different. So this one is going to use something named set content. So we're going to say EM dot set content. So the content of the email is the body. So once we have this done, this is what we need. The next thing that we want to do is to actually come down here. I'm going to create a Context. But for us to create this context, we need to import something named SSL and SMTB library. So I'm going to come up here and then we're going to say import SSL And then we also have to import SMTB library. So all of this should be pre installed when you install Python, so you don't need to run pip install anything, they should already be installed. But if they are not installed, then you can just look up how to install them. I'm pretty sure it's very straightforward. So what we want to do now is to come here and say Context SSL dot create default context. So this is what we want to use. And then we're going to have with SMTP library dot SMTP, when you say underscore SSL, we're going to use the Gmail SMTP. So I'm going to say SMTP dot Gmail dot com. We're going to say 465. And the context is equals to this context right here that we specified. So context equals context. So once we have that, we're going to say with this as SMTP specifying all of this as SMTP, then we're going to say SMTP dot login. So we want to log in with the email sender and the email password, which we specified already. And then we're going to say SMTP dot send mail. Now this is when we're actually sending the mail, what this is doing is this is logging in with those, you know, those, these particular credentials that we gave it. And then once we have been able to log in, we're not going to send email. So from email sender, this is the person I was sending from email sender, email receiver, sending to and then EM dot as string. So basically, it's converting this EM, which is the instance of this email message that already has all these details now, send or a string. So one is send all of this. And this will actually work perfectly. But there's one more thing we need to do is to specify the person that is receiving the email. So for these, let's actually use a temporary email, we'll come to Google. And let's just say temp mail. So this temp mail is a site that generates temporary email for us. And what we can do is just to copy the temporary email that it generates. And then we're going to use this to test. And once we use it to test, we're going to send the mail to this. So if the mail lands in here successfully, that means our program works. So let's come back in here now. And in the email receiver, I'm going to paste that in. I'm going to paste that email in here, we save that. Now everything should be working perfectly. Let's run this and see what happens. So that's going to take a while to run. And we don't get any error response. So that means everything should have worked successfully. Let's go back and see if you come here. Now you can see that it says from code we told me at gmail.com. Don't forget to subscribe. If we open up that particular email, and we read the content. So you can see don't forget to subscribe when you watch a video, please hit subscribe. This is exactly what we specified here. If we close this down, don't forget to subscribe when you watch a video, please hit subscribe. So as you can see, this has worked successfully. This is the new way of sending mail with Python. Because as I said, the old way is no more working basically. So what we need to do now is to adapt to this new way. So I hope you understood everything we did in this video. Let's quickly go back to Now talk about what we did. First of all, you have to go to your account and set up the two factor authentication and generate the app password. Then you need to come here, import all the necessary stuff. The first thing you need to import is this email message. So we want to specify the sender, the password, the receiver, and the subject. Then once we specify all of that, we can use that to create an instance of this email message, we save that as EM, then we imported SSL and SMTP library, then we use that SMTP library to actually log in and send the mail. So I hope you understood everything we did in this tutorial. In this tutorial, I'm going to show you how to build a simple word replacement program. So the reason for showing you this is to introduce you to the replace method in Python. So what this does is that it takes a string, and it replaces some words in that string with another word. So this is very easy and straightforward. What we just need to do is to have a new function. Let's call that function replace word. And in there, we're going to have a string. And let's say this string is, I guys, I am Tommy. Let me say, and I write, and what we're going to do is to have a variable that says was to replace. So this is the word we want to replace. And let's collect this from a user. So let's say, enter the word to replace. And we also want to have just the normal word that is going to be replaced. So what this we're going to say enter the word replacement. So we can just call this word replacement. And then we're just going to print out the string, right, dot replace. So this dot replace is a method that allows you to replace a word with another word in a string. So we're just going to say word to replace, we want to replace a word replacement. So this is all we need to do. And what we just need to do now is to call this function. So let's call this function replace word. So now let's just run this. Once we run this, it asks us for the word to replace, we'll say I and enter the word replacement, let's just say a. So as you can see, it changes every time we say I to a says a guy, I am Tommy and a. So that is how to use this basic word replacement, you know, method, and you guys need to build, you know, whatever you want to build, or whatever you think of. But that is how to build a simple word replacement program. In this tutorial, we're going to be building a simple calculator with Python. So what we're going to do is to first define the functions. So we're going to first, let's say, define the functions needed. So the functions I'm going to define are add, sub, more, and div. So this is for the addition, subtraction, multiplication and division. Then once we do that, we are going to print the options to the user. So print options to the user. So these options will be, you know, add, subtract, multiply, or divide, or exit. So then once the user inputs the option or whatever they want to do, let's say they want to add, then we are going to ask for the numbers. So ask for values. Once we get the values we need, then we are going to use that to call the functions. Once we call the functions, then anything that is done in that function is going to happen. But then we're also going to add a while loop to continue the program until the user wants to exit. So this is the steps are going to follow to build this program. And let's just get started. So I'm going to remove all of this now. As we said, we are first going to define the function. So what we want to do is to say def add. And this is going to take two inputs. So let's say A and B. And we can just easily return A plus B. But what we can do to make it look better, we can just say answer is equals to A plus B. So that is the answer. But what we're going to print to the user, we're going to say print. Let's convert this to string A. Then we're going to say plus. So we're using concatenation to like form a sentence with the input that user give us on the answer. So then we're going to say plus string B. Close that. Then we're going to say plus, we're going to open another. And then we're going to say plus string, converting the answer to a string. So what we're doing here, we're just saying A plus B is equals to the answer. But we're converting all of these two strings, so we can be able to concatenate them. There's another way of doing this of using concatenation, you can also use comma like saying something like we can just print a comma B, something like that, then we don't need to convert it to string or even use concatenation. But we can just stick with this if we want. So once we have this, that is the function needed to just add two numbers together, which is a very simple basic function. Then we're going to do the same thing for the subtraction. So we're going to say, define sub A and B. I'm going to say answer is goes to a minus B. And then we're going to print exactly the same thing. And what we're going to print is the same thing we printed before a plus minus just going to do that. concatenate that with string of B. Then we're going to add that. And then we're going to say string answer. So we're going to do the same thing again. For the multiplication, so A and B. And so is equals to a times B. And then we're going to print exactly the same thing as a string A plus we're going to use the asterisk sign, which is also the multiplication sign, then concatenate with string B concatenate equals to plus string answer. Now for the last function, divide A and B, just like we've been doing, we're going to say answer equals to a divided by B. And then we're just going to print string of a concatenate plus string of B concatenate equals to concatenate with string answer. So this is all we need. So we have defined the function successfully. The next thing we want to do is to print out the options for the user. So what we're going to do now is to print a addition. Now we're also going to print B subtraction. We're going to print C multiplication. Then we're going to print G division. And then we're also going to print the last one so that we will know when to break out of the while loop, exit. Now we have this what we want to do is to now have a variable name choice. So this choice is going to be equals to an input. And that input is going to be input your choice. Once the user do that, we're going to say if choice is equals to we use the double equals to in Python. So if choice is equals to a or choice is equals to capital letter a just if the user decides to input small letter or capital letter, we got them. So we'll say, let's just print addition. And then we're going to ask for the input to input. And then we're going to say input first number. Well, then we have to convert all of these to an integer because we're dealing with numbers. And then we're going to do exactly the same thing for the second one and say input. I'll just say them to input second number. And once we have the two values, the user wants to use to calculate what we're just going to do is to call the function add by giving it these two values. So this is what we just did, we collected the two values from the user, or the two numbers, then we call the function add by giving it these two numbers, which is what is needed here. So once that is done, the next thing we just want to do is to have another condition by saying a leaf choice is equals to B or choice is equals to capital B. Then we're going to print subtraction. And a just like we did is equals to integer of input input first number and B input second number and subtract A and B. Now we're going to do the next one, which is also going to be as if choice is equals to C or choice is equals to caps, let us see. Then we want to print multiplication. And then we also want to collect the same thing and run that function using the two values. And for the last one, we're going to do leaf choice D or D. And then we're just going to say, print division, collect the two values, then use the function using those two values or call the function using those two values. So now that we've done that, the next thing we want to do is to say a leaf choice is equals to E or choice is equals to capital E. Then we're just going to print program ended. And what we're just going to do is to call the quit function and stop the program. So once we do that program is ended, we've got the quit function. So the old thing should be working now, the old program should be working. And we don't need this choice, because that's not the choice we're using. So the old program should be working, we define all the functions, show the options to the user, allow the user to pick what he wants, collect the values and then call the function. Now let's see what this gives us. So let's say I say B subtraction, first number is five, second number is two, five minus two equals three. Good. That is what I want. But as you can see, once it gives me the answer, it cuts out of the program, what I want it to do is to keep looping it until I tell it to exit from the program. So I want to keep calculating, you know, multiple numbers until I tell you to stop. So to do this, what we need to do is to use a while loop. So right here before this sprint, let's say while true. So while true is going to do this for us, I was just going to pull all of this under the while true loop. So this is just going to keep looping it, it's not going to stop until I call this quit function. So everything is going to keep going on to the user inputs E. Now let's run this and see. So let me choose C, first number is four. And second number is four gives me 16. And then asks me to input again. So let me choose a free five gives me eight, ask me to input again, that is working. Now if I click on E, it says program ended, and it cuts out of the program, or it breaks the program. So that is working successfully. And just one more thing we might do to make it look better is to add a break. So we're going to have the slash and N, this is just to give it some spacing. So let's add it to all of the print and the functions. So that when we let me show you quickly what that does. So let me say C, five, five. So as you can see, there is a little bit of space here before the next, you know, program starts running again, just so everything doesn't look rough. So that works successfully, everything is working. This is the basic calculator, which we built, I hope you understand everything we did in this tutorial. And that is working successfully. In this tutorial, we're going to be building an email slicer. So what an email slicer is, it's that it is a program that takes a particular email, and then slices it into the username, and then the domain. But we are also going to slice it into username, domain, and the extension. And the extension is let's say it's at gmail.com, the extension is dot com, or just come. So let's do that. Before we get started, let's walk through what we're going to do to achieve this. So the first thing we want to do is to collect email from user. So once we have the email, all we want to do next is to then slice or split the email using the art. And once we do this, basically what this is saying is that for example, let's say we input something like, hello, at code at code with Tommy dot com, if we input this, we're going to slice the email, or split the email using this art, that means it's going to take this splitted as one, I'm also going to split this as another one. But then once we have this, we're going to save the first part, which is this part, which is hello, as the username. And then once we do that, the second part is gonna be let's say saved as domain. Then what we want to do is now split this domain. So we're going to split domain using the dot. So that means this now we're going to split this code with Tommy dot com. And the first part is now going to be the domain, which is code with Tommy. And the second part is going to be this.com. So what this is saying now is this is the first part, which is the username that we add already. And the second part from this initial split is code with Tommy.com. So what I'm going to do is now split the second part again using this dot. So then we're going to have code with Tommy, and they were going to have come. So let's do that real quick. So what we just want to do is to have a new function, we can just name this function main. It's not going to take any input, or just gonna, we can print something and say, welcome to the email slicer. And once we have this, let's just print a blank sentence or blank word, so we can have spacing. And then what we want to do after doing this is to just collect the email so we can say email input is equals to input. I'm going to say input your email address. So once you input the email address, or want to do nice to slice it, so we're going to use a particular format. So we're going to say user, command domain. So let's send this to username. So this username, command domain was split, it is this is going to take the first part and the second part of the split. So this is going to be close to email input, dot split. So we're splitting it using the art. So what this is going to do now is I want to split it, the first part is going to be close to this variable and the second part is going to be close to this variable. So now that we have that splitted, we have the username done, we can print the username. But for the domain, let's now say domain and extension. So what we want to do now is to say domain, the split using the foot stop. So what this is doing is updating this domain with the something like this. So hello, at code with Tommy, that come. So now we add this as a domain in the initial split, once we split, when we split it using art. So we add code with Tommy dot com as a domain, but we now want to update the domain to just be code with Tommy and then the extension to be calm. So what we're going to do is domain equals domain dot split using full stop, and then it's just going to do that. So what we can do now is we already have that those variables and we've given them their values, we can just print this. And we can just say, username. And they just use comma, so vision concatenation. So we can just say is username. And we're going to print domain is domain. And then we're going to print extension is extension. So now this should be working. Let's just call this function. Save this and run it. So now let's see. So it says input your email address. Now let me use the example I've been using all along. Hello, at code with Tommy dot com. So you can see it says the username is hello, the domain is code with Tommy and this is the extension. So that works successfully. We can take a look before that and just keep, you know, looping it by saying, wow, you know, so we can do, let's quit this can do while true. We can just keep doing this. And once we just run it. So let's just say something that's blank at gmail.com. So it says blank gmail. And that is the extension. And it asks us to input again. So now we can say hello at code with Tommy dot com. It does that again. So this email slicer is working perfectly and successfully. In this tutorial, we're going to be looking into binary search in Python. So we're going to be writing a program that performs a binary search operation using Python. So a little bit of explanation, a little bit of context before we get into the coding part. So binary search is a searching algorithm that works by repeatedly splitting a set of data in half to the target value is found. So let me explain what this actually means. For example, what binary search does is that it takes the list of data, a list of ordered data, and it takes a target. So it keeps splitting that list of data in half till it finds that target. So for example, let's just say we have a list that is 123456789, right? And there's a 10. So we have this list. And then what we can do with the binary search or what binary search does, let's say that we have a target that is we are looking for three, then what it's going to do is that it's going to split this data into half. So as you can see, what it's going to do is going to get the first index and the last index added together then divided by two. So this is zero. And this is 0123456789. So this is nine, then it's going to do 0.0 plus nine, basically something like this zero plus nine, then it's going to divide down so by two. And whatever you get is going to split that is basically the middle value. And it's going to use that to split the data into two. So it can split this data into two from here, then that target value, let's say we are looking for three as a target, right? So that mid value that we got, let's say we got a mid value of 4.5. But then it just discards the point five and uses four. So this is for right with an index value of four, then is going to check if three is greater than or less than therefore, since three is less than eight is going to discard the whole list size after the middle value. So this is going to be deleted. And then it's going to focus on just this particular list, then is going to do that again, it's going to split it into half. If three is greater than that, let's say we get this is our fry, since three is equals to that particular mid value or middle value, it stops the program, because the target has been found. But imagine the target was two, what it's going to do is that is going to discard all of this again, from here, and then is going to look into this particular list, then is going to run that program again, or run that function again, and it's probably going to see two as the value. So that's where binary search works. It takes a list computer repeatedly splits it into half until it finds the target. So now let's get into the actual coding part of how we're going to do this. So if we want to brainstorm this, let's write a few steps which are going to take. So you say with that, the first thing we want to do is to let's just have some comments that says what we want to do. So we are going to have a function that takes a list, and let's say, a target parameter. So this is going to collect lists, it's going to collect two parameters list and a target. And once we have that, we're going to have different variables, multiple variables. And let's say the variables are middle. So we need to know the mid value, the start value, we need to know the end and the amount of steps. So in binary search, the steps is the amount of time it has looked through for the data or it has split that set of data into half. So imagine we have to split that data into our three times before we get the particular target, that means this amount of steps gone through is three steps. So we also have a variable that tracks that. Now once we do that, we can either use a recursion, we can either use recursion, or a while loop to keep because as I say, we're going to repeatedly split that data. So we can either use a while loop, but we're using a while loop, that means we are updating the data by ourselves manually. And if I've been a recursion, we're just going to call the function inside yourself again to keep splitting data. So you're going to understand this when we get more into the coding part. And after this, what we are just going to do is to basically increase the steps each time we step through it. So increase steps each time a split is done. Then once we increase the steps each time a split is done, we are now going to have some conditions. So conditions to so we're gonna have some conditions to do something like if the target is the middle or if the target is less than the middle, or if it's greater than the middle, then what to discard the other part of the list. So conditions to tag to track target position. So once we have this, then as I said, we're going to use a while loop. So we're just going to return something like minus one to, you know, keep, then we're going to use a while loop that says something like, while the stats is still less than or equals to the end is going to keep looping. So let's just close all of this now. And let's just get straight into the coding. So the first thing we want to do is just to have a function. So binary search function. So this binary search function, as I said, is going to take list. And let's say element, we can say target, we can say element. And if you want to say, and in here, what we want to do is the same media equals to zero. So these are the variables that we are defining our media is equals to zero start is equals to zero. The end is asked to be the length of the list that we are collecting. So this list and the steps initially is equals to zero, because it doesn't split data yet. So now that we have all of this, next thing to do is to use a while loop. So I'm going to say while start is less than or equals to end. So basically, we want to keep doing this until this for this condition is no longer true. So we say while start is less than or equals to end, start is the we're going to also update the start this start variable, when we split the old list, but this start is the beginning of the current list. So as long as that is still less than the end, right, we want to continue doing this one to continue looping through this particular code, which we're going to do under here. So what we want to do now, we actually want to print something that shows the user the amount of steps and like, the, let's say the list that is remaining. So like each time we discard a list, or we delete some part of the list, we want to show the remaining list and the amount of steps we've done. So to do this, we're just going to use a little bit of concatenation. So we'll say steps, step, commerce, steps, to the space. And let's say something like, so we're going to do comma yellow. So yes, and we're going to have the list, which is this list, then we're going to let it start from the start and end at the end, we have to add plus one year. So what this is, is that we are now saying show this list, but show it from the index of start, which initially zero and end, which initially is the length of the string. So let's combine this to a string. So we don't get no errors. So this is what it's going to show us. So initially, when we run this particular program, it's just going to show us this list, the whole list that we pass into it, because you're just showing us from the start, which is zero to the end, which is the length of the string. But this is for now, because when we update this start as, let's say, five, let's say the status five, what it's going to do is that it's going to start this list from the index variable five. But for now, it's still zero. So once we have this done, let's say steps. Now we want to update the step. So we're going to say steps equals steps, plus one. And middle, this is one of the most crucial parts. So this is when we're actually splitting the data into half. So start plus end, as I explained earlier, we add the start and the end and then we divide it by two divided by two, then we're going to say, if the element, which is the target value, basically, is equals to least middle. So if the middle which is what we got from the value we got, if that is equals to the element or the target that we're looking for, then let's just return me do as the data found. But if there's another container says if element is less than least middle, so that means if is less than the least from the middle, what we want to do is to update the end as middle minus one. So what are we doing here, basically, what we're doing is that we're saying if this element is less than the middle list, so let me just have a comment that explains what this is doing. So if element is less than middle list, so what he's saying is, we have a list, right 12345. And he's saying if the element which is, let's say to say element is two, obviously, the middle, the least middle, which is this particular stuff in this example is three. So it's saying if elements is less than that, so if element which is two that we're looking for is less than three, then want to say the end, which is now the end of the new list is equals to the middle minus one. So we want to say the middle, which is three, minus one. And the reason why we did minus one is because all indexes start from zero. So this will be 012. So this is now the new list because the end is now here. So basically, it's going to discard all of this and create a new list that only has 123. So that is what this part does here. So when we have the end now updated, once it comes back to loop again, and in this place, the end is now updated to what to three, so it's not going to be is basically not going to show the initial list again, it's not going to show the updated list, which has already cut out some part that is not needed. So once we know about that, the next thing to do is to have like an so we have a condition right updates the end that condition is when the element is less than the middle. But what if it is greater than the middle, so then once you start is equals to middle plus one. So just very similarly to very similar to what this was, this is just saying else that means if the element is not less than the middle, that means is greater than the middle, then once updated, start to middle plus one, if I quickly use that same example, 12345. And the value is, let's say four, it is instance. So the middle is three. So now that means if the element is greater than least middle, that means if four is greater than three, which obviously is greater, then the start is now middle plus one. So middle is three. So we're going to say middle plus one, the, what we're going to do now is 012, right, then we're going to add one to that. That's why we're going to have 0123. So from here is going to discard the rest of this. And it's just going to only have this particular list as a new list. So once we have this done, we have updated all the values that we need. The next thing we want to do is to just return minus one. So we're just going to have something that says return minus one. And this is not part of the loop. This is outside the loop. So basically, when the loop is done, so this is the very simple, like function to do this. Very straightforward. And what we can just do now is to actually test this function and see how well it is working. So we are gonna run this function. Let's have a list. Let's say my list is equals to 123456789. And let's say our target is equals to say we are looking for two. Now we can run this particular function by saying binary search, and we're going to give it my list. And we're going to give it target. Now when we run this, let's see what it gives us. So as you can see, it shows just two steps, because we are looking for two. So it's cause this is down to this list. And the answer is basically in this list, let's say we're looking for one and let's see if that will work for us also. So you can see that it shows three steps now, cuts this list down to this list, then you also cut this list here to give us one, if I'm looking for nine is going to do the same thing. So let's run that. So it cuts it in three steps and gives us nine. So let's say we are looking for let's say we increase this, you can test it out by just, you know, increasing the values and do whatever you want to do. And we just have 12. So it still gives us three steps. So as you can see, everything works successfully, we've been able to perform a binary search using this very basic code. There are multiple ways you can actually code a function to perform a binary. You guys I said you can use, you know, a recursion, which is where you call the function inside itself. So instead of us, like, basically, using the all of this updating these values, what we're going to do is we're going to call the function with these updated values. So somewhere like, instead of using the while loop, we can just say after checking if all of this is true, then we write here where it says less than, and we update this, what we can just do is we just call binary search here again, with the new list and all of the new data. But this obviously does the work for us. And there are various reasons why you actually want to use binary search instead of a normal search. So the most important of them is because of the the time complexity. So if you're using a less than normal say like a linear search, or that which is the normal way of searching stuff, and the linear search is where he just steps through every single data in the list until it finds that value. So as I said, the reason why you want to use binary search instead of linear search is because of the time complexity. binary search is far more quicker than linear search, because binary search doesn't have to look through every single value in the data or in the list. But for linear search, it has to look through every single data till it gets to that particular target we're looking for. For example, as we said, because we're looking for 12, it just splits this data and basically cancels all of this. So he doesn't look through that because he knows is the data we're looking for is normal there, then it focuses on where it thinks is going to be split all of this again, and you know, keep doing that, which saves more time. But imagine we're actually using a linear search. So let's see our linear search is going to work. And we're looking for 12. What we're going to do is something like for i in my list, then we're going to say if i is equals to 12, then we'll say print found. Now the drawback about this is that it has to go through every single data. So it's going to count from 12345, all the way to the reaches 12. That's when it's going to print found. So this is going to take a lot of time. And that's why it has a bad time complexity in this particular instance. So you never want to use, you never want to step through or go through every single data in the list. Instead, you just want to use a binary stitch to make everything quicker. So I'm just going to undo all of this and go back to our code. So this is the basic way of you know, building a program to perform a binary search. In this tutorial, we're going to be building a quiz program. So this is quite straightforward. It's just where we're going to have a dictionary that contains a list of like, questions and the answers. And then we're going to ask those questions and answers to the user. And the user is going to answer the questions. And then we're going to tell the user the score after and the percentage they got. So let's quickly go through the steps of everything we need to do. So first of all, let's deactivate that, disable for Python. So first of all, the first thing that we need to do is to have a dictionary, dictionary that stores questions and answers. Then what we need to do is to have that dictionary loop through that dictionary. Before we loop through the dictionary, let's actually have a variable that tracks the score of the player. Then we want to loop through the dictionary using the key, key value pairs. And once we loop through that, while looping through that, we just want to show display each question to the user and allow them to answer. Tell them if they are right or wrong, then we want to show the final result when quiz is completed. So this is the steps we're going to follow. First going to have a dictionary, a Python dictionary that stores the question and answers, we can just name this quiz, then we're going to have a variable that tracks the scores, loop through the dictionaries and the key pair, the key values pair, then display each question to the user and allow them to answer and tell them if they are right or wrong. And then show the final result is actually leave this year and follow these steps. So the first thing we're going to do is to have this quiz dictionary. But in this dictionary, let's say the key is question one. And the value is actually going to be another dictionary in there. So something like this. Yeah. So that is what the value is going to be. So then the question is going to be, let's say, what is the capital of France? And let's say the answer is Paris. So that is one question that has all the question and answer, we need to make sure we have the comma here so we don't have any error. So this is one question, question one, and it has a value of question and answer. That is one, then we're going to go to the next one, make sure you have your comma, question two. Same thing, question. And then we're going to say something like war is the capital of Germany. And then I'm just going to have the answer. And that should be Berlin. We're going to keep going. Right here we have our comma, we do question three. We have a question. Let's see, let's say war is the capital of Italy. And there's our answer as Rome. So just to save time, we're going to copy and paste this. So let's copy and paste this four more times. So right here, two, three, four. So right here, we're just going to change this to four, changes to five, change this to six, changes to seven. And let's say Spain, Madrid. And let's change that to Portugal, Lisbon. And then let's say Switzerland. Burn. And for the last one, let's say Austria. You know, so now we have all the lists or dictionary of the questions. And in each of those questions, we have the question and the answer. So what we can do now is to loop troll of this show it to the user. And then, you know, continue from there. So before we do that, let's see, since we have a variable that tracks the score, so this very easy, just a score equals to zero. So initially, the user has a score of zero. That is all we need to do for that. Then the next thing we need to do is to loop through, but we're going to loop through this especially not the normal loop, because there's a dictionary want to loop through using the key and the values. So says loop through dictionary, right? What we're going to do is to say for key value in quiz dot items. So this is where you can loop through a dictionary. What we just want to say is print the value. So from the value, what we want to print is the one that the value of the key question. So I'm going to say question. It's going to print that then answer is going to be equals to input answer. So once we say that, what we're now going to do, so we've printed the question, and then we're asking for the answer, what we now want to do is check if this answer is actually correct. So say if answer dot lower is equals to value, answer the lower, then the user is correct. So let me tell you why we're using dot lower. So basically, because Python is case sensitive, if we don't use dot lower, what it's going to do is that imagine the user types burn, but doesn't put the caps letter on B, let's say the user types, this is going to make it as wrong. But what I'm doing is I'm converting whatever these are right into lowercase. And I'm converting the main answer also into lowercase. So if both of them are equal, then the user is correct. So then we can increase the score by one when the user is correct. And after increasing the score, we can print the score to these actually after every time. So let's just do that. So we can say your score is, let's just add, let's convert it to string first of score. So that is the user score. And we can just have our else. So if this is not true, then that means the user is wrong, then let's print wrong. Then let's actually tell them the correct answer. So we'll say print. The answer is then we're going to say value, but now I want to say answer. And let's also print the score. So let's just copy this right here. And that should actually work. So let's see what this is going to do for us. Let's save this and run it ask us for the capital of France, Paris. Correct, my score is one Germany. So you can see now now if I mix, let's say, with capital letter and small letter, it still tells me I'm correct. That's because of this particular command, this particular condition right here. That's why that is useful. So my score is to imagine I okay, since we already have that we can test it, what I wanted to do is to test, let's say we have all caps, imagine big, this is what this is not all caps. And this is all caps, if we didn't have these right here, it's going to say is false. But because I took care of that, it's going to say true. So I have three. So let's start missing all of it. So let's just. So basically, I landed on score of three, right? So let's just take it further. First of all, everything just looked too packed. So we can just use to have a little bit of spacing. So right here, where we have score, we can just say print blank, there's also plain blank there. And also right here, print blank. And we'll do the same thing again. So we have that done. What we actually want to do is that after all of these, we want to tell the user its final score. And we also want to tell them the percentage. So let's say print. I'll say something like you got string score plus out of seven of seven questions. So you got let's say three out of seven questions correctly. Then let's print out the percentage. Now we can see your percentage is concatenation. Let's first make sure we're converting whatever we're doing into string. So we're going to say score divided by seven times 100 to convert into a percentage. And let's just add by saying, let's concatenate percent just to have the percentage sign. So this should work. Let's see. Let's quit that and reload it. So let's just get like two out of it. So Paris, you can see down now there's spacing, so we can see it well. So we've got into let's start getting a little bit wrong. So you can see it says I got two out of seven questions correctly. And my percentage is all of this, this is a long number, what we can do is actually convert this to an integer, so that, you know, it doesn't show like all of these decimal points with it. So right here, we can just say int. And you actually want to convert it into an integer before converting it to a string, you don't want to convert it to a string before converting into an integer because you can't concatenate an integer and a string together. But now this should work. Let's try it out and see. So I'm just going to get let's say three out of it. We have France, Paris, Germany, Berlin, Rome. So as you can see, it says I got three out of seven correctly, and the percentage is 42%. So that is how to actually build like a very basic quiz app or quiz program with Python, as you can see, that was very easy to build didn't take a lot of time. And I hope you understood what we did to this point. In this tutorial, we're going to be showing you how to convert a text or a link to a QR code using Python. So this is very easy, because there are a lot of libraries out there that already allows us to do this. So let me just walk you through the steps on what we're going to do. So the first thing we want to do is to install all the libraries needed. Once we install the libraries needed, then we are going to create a function that collects the text and converts it to a QR code. Then we're going to save the QR code as an image. Once we save the QR code as an image, then we are going to run the function basically. So this is the basic steps that we're going to take. And let's just go ahead and do this. So the first thing we want to do, let's open up a new terminal. And let's install the packages needed. So I'm on a Mac, so I'm going to use PIP free to install. If you're on a Windows, you don't need to use PIP free, just type PIP. And I'm going to say install QR code and image. So I need these two libraries. So what I'm going to do is to install QR code and image, I already have them installed. So as you can see, it says requirement already satisfied. But for you each go ahead and install that. So once I have that done, I'm only going to import QR code, I don't need to import image. Once I have that imported, let me just have a new function, let me say generate QR code. And it's going to take a text or URL or wherever you want it to take. And then what we want to do is to say QR is equals to QR code dot QR code. And version is equals to one and error on the scope and correction is equals to QR code dot constant dot error on the score, correct underscore L. And box size is equals to 10. Unless a border should be like, five, or let's leave it at four. And that is done. The next thing we just want to do is to add the data to this QR. So this is like going to generate a new QR code. But what we now want to do is to add this text or the URL, wherever the user inputs, we want to add it into this QR code that we just generated. Let's come here and add full stop to avoid the error. And then we're just going to say QR dot add data. So this is just going to add the data for us. I'm going to say text and QR don't make, let's make it fit. So fit equals true. And image should be equals to QR, the make image. So this is going to make the whole image of the QR code with the data and everything. So when I fill it with a color of black, you can input whatever color you want. And the back color should be white. So as you know, most QR code has this particular format, white and black. And then let's just save this image. So we're going to say image dot save. And let's name it something like QR image dot png. Now this is working perfectly. What we just want to do now is to run the function. So we can say generate QR code. And let's give it a text, I'm going to give it a link. So let me say HTTPS www dot code with Tommy dot com. And now once I run this, this is going to create a QR code based on this particular format. And it's going to give you this data, which is code with Tommy dot com. So let's run this. So it says it has no attribute error. So we just need to come here and change that to error. That was a typographical error. So let's save that and run it again. We don't have no response. But if we go into our computer right here, so I am in just in my root directory. And as you can see, I have this QR code named QR image. So that is the QR code has been generated or that has been generated based on this format, or based on this text, this URL. So if I scan this QR code, it's going to give me this particular URL that I used. But let's take it further and say we want to ask the user to input their own URL, then we generate the QR code based on the URL. So we're just going to say URL equals to input, we're going to ask the user, enter your URL, and once they enter that, we're just going to generate this based on the URL. So let's save the let's say this is 001. Let's just run this. Now once we input a HTTPS YouTube dot com slash code with Tommy, no response. But if I come in here, you can see that I have a new code, different format, it looks different from the initial one. Once I scan this, you can scan this using your phone or just scan it online or anything is going to take you to the site, which we input which was YouTube dot com slash code with Tommy. So that is how to create a basic QR code generator. There are very there are various ways you can use this, you can use it on your website, to you know, do multiple things just automatically convert particular text to QR code for your users. There are a bunch of ways you can use it. And that is how to build it. In this tutorial, I'm going to show you how to build an interest rate monthly payment calculator. So it's a program that is going to take the input of, you know, the principal amount borrowed, the annual interest rate and the amount of years, and then it's going to tell you how much you're going to pay each month for the total amount of years till you pay off the loan back. So before we get started, let me walk you through the steps of what we're going to do. So the first thing we want to do is to collect the necessary input. And these are the principal. And this principal is the initial amount borrowed or the amount, the loan amount, and APR, which is the annual interest rate, and then the years. So this is the amount of years that the they're going to use to pay the loan back basically. So once we collect those inputs, what we're going to do is then calculate by going to calculate the monthly payment. And we're just going to show that to the user. So this is all we need to do, to be honest, this is where the main work is calculating our monthly payment. And I'm going to walk you through step by step. So let's just get straight into this. So let's just create a function. So we create a main function, it's not going to take any input, or we can just do we can print something and say this is a monthly payment loan calculator. So once that is done, we can print, let's just print this to give some spacing, and then want to get the input from the user. So the principal and note that for this type of calculation, since we're dealing with money, we have to use float. So we have to convert this to float. So let's have an input and say, input the loan amount and one of the APR, which is the annual interest rate. So input the annual interest rate. And then this should be a float. And the amount of years. This should just be an integer. And we say input. And let's say input amount of years. So once we have those inputs, we can go straight to the next step, which is calculating the monthly payment. This is the payment which you pay monthly to pay the loan back. So let's say monthly interest rate. So we can say APR, we have to divide this APR by 1200. So this APR, which is the annual interest rate, we divide that by 1200 first. So that's to get the rate, then we're gonna say months equals to the amount of years, which we collected multiplied by 12. So just to calculate the amount of month, which is going to be used to pay this loan back, then we can calculate the monthly payment. So we can say monthly payment equals to exchanges to, let's say amount of months, a monthly payment can be because the principal multiplied by the monthly interest rate. Then we divide this by I think we should open a bracket here. Should we Yes, we should. And we say one minus then we open another bracket. So we're basically using board mass right here. One plus monthly interest rate as inside that bracket, then outside that we multiply it. We use the asterisk sign twice. And then we say minus amount of month. So this is going to do the work for us. And then we're just going to display the result to the user basically. So we can just say print the monthly payment for this loan is this is concatenation, let's say, monthly payment. So this should work fine. Before we run this, let's say main. So all of this should be working. Now, let's test it out and let's see. So let's say the loan is 20,000. We rate of 3% and input amount let's say five years. So it says can only concatenate string not float. So what we just need to do is to change this to a string. And then let's run that again 20,003 and five. So it says the monthly payment for this loan is 359.373 a and all of that. So let's just make this look more presentable. Let's cut it to only two decimal points, because that's what money ends up two decimal points. So to do these, we are not going to need to convert this to string no more. Let's remove this. And we're also not going to use this. Right, yes, let's remove this. What we want to do, we're actually going to use a particular format by saying percentage dot two F. So the two F what it does, it cuts, it cuts this to two decimal places. And then we're just going to say percentage. And that should do the work. So I save it running 20,000 now, three percent five years. So it's a 359.37. So if you want to use dollar sign pounds, whatever, you can just add it right there by saying dollars or whatever you want to add. So this does the work for us. And everything is working fine, as you can see. So what we can also do is to just use a while loop to you know, keep looping this until the user doesn't want to calculate anything normal. Or you can do that if you want to do that. So let's run this again and see what it does. Let's try with like a larger amount to million and with a rate of a crazy rate, let's say 40%. And two years. So that's going to be 122,000 every single month. So this is how to build a basic interest rate calculator. So as you can see what I did, we took the inputs, we calculated the monthly interest rate, and then we calculated the monthly payments, I've just printed that to the user. So this is how to do that. In this tutorial, we're going to be building a random password generator program. So let's outline everything we're going to do to build this. So the first thing we want to do is to ask the user if they want to generate a password or not. Then once we ask them if they want to generate a password, if they say yes, so if yes, yeah, so if yes, we don't want to generate a password yet, we want to ask for the password length. So if yes, ask for password length. And once we asked for the password length, what we just want to do is to generate a password. So we just generate the password, and then print the password. So once we print the password, that program is done. But if they say no, then we want to exit the program. So if if initial response is no exit program. So this is the island we're going to follow. And we're going to get into the more coding stuff in a bit. So this is what we're going to do. We're first going to ask, ask the user if they want to generate a password or not. Once they say yes, then we're going to write a function that's going to generate a password. In that function, we're going to ask for the password length. And then we're just going to generate the password and print it to the user. So let's just go ahead and do that. So let's clear this up. So the first thing we want to import a string. And then we want to import random. Once we import both of these. The next thing we want to do is to have a variable name characters. So what these characters is going to do is that it's going to take the basically a list of all the different characters that we want to generate our password from. So this is going to be a string dot dot ASCII letters. I also want to use the string the digit. And let's actually add one more, we want to use some random signs here like this signs. So we also want to use all of these signs right here. And this should actually be a list. So we want to say list of all of this. So I converted that to a list. So this is basically the amount, not the amount of characters, basically, the characters want to generate a password from. So when is generating password in my peak, let's say two characters from here, three classes for me on one character from here, it depends. So that's going to be random. Now we want to have our function that says generate password. And now that we generate a password, we're gonna say password length is equals to an integer. And let's say how long would you like your password to be? So that is the question we're going to ask the user, or whatever the user input, we're going to convert that to an integer. So now that we, you know, have that, what we want to do is to shuffle this character. So it's not just going to be like, let's say it's not just going to pick two from here, then three from here, then one from here, like, in order, we just want to shuffle it so it takes a randomly. So what we're going to do is to say random dot shuffle characters. So once we shuffle that character that is done, the next thing we want to do is to say, as well as have the password as an empty list. So once we do that, we want to pick random characters now from this, from the list. So what we're going to do is now use a for loop and say for x in range of password length. So what we're going to do is to say password, which is this password, dot append random dot choice. So it's going to take you randomly from the characters. So once it takes it from the characters randomly, now we want to shuffle the password. So we're going to say random dot shuffle password. So the password that we just got, you know, is appending characters from this list, right into this password list. Then once we have that, we also want to shuffle it again, just to make it more random. And what we're just going to do is to now convert this list because we want it to be a string. But right now we initialize the as a as a list. So what we're just going to do, we're going to say print, we're going to say password is equals to blank dot join password. Once we do this, now we can print password, not want to print the final password to the user. So we're going to say print password. So now we printed that we're just going to do we have the generate password working, we have the function should be working right now. So now, we're just going to run the part the program normally, and we're going to say, we're actually going to ask the user. So we're going to say option is equals to input. Do you want to generate rates of password? Then we're going to say yes or no. So that is what we need. Then we're going to say if option is equals to yes, then we're going to run the generate password function, which we just did right here. But if option is equals to no, so we're going to say Elif option is equals to no. Then we're going to say, let's print something like program ended. And we're going to run the quit function. So that's going to quit our program. But then if it's something else, we're just going to print invalid input. Please input, yes, or no. And we are going to quit the program. So this should be working out everything should be working fine. Let's save this code. And then let's run it and see what it gives us. So you ask us, do you want to generate a password? I'm going to say yes. Okay, let's first change that. That is a bit together. So it should be something here. Like this, yeah, that should be all right. Now let's save it and run it again. So now do you want to print the password? Say yes. How long would I like the password to be less than 17? And then it prints a random password or 17 letters. So let's run that again. Say yes. And I want the password to be less a 191. It's going to print a long password of 191 characters. Let's run it for the last time and test if we say no. So once we say no, it says program ended, which is what we want. And let's test if we write something else. So let's just write a random stuff. And it says invalid input, please input Yes or No. So that is a very easy simple way on how to generate random passwords using Python, you can integrate this, let's say you you learned how to build a web app with Django or Flask or something or Python framework. And then you want that when a user is trying to register, you want to have a feature that just allows them to generate a password for them, you can input this type of, you know, logic or this type of programming there, and it's just going to generate a password for your users. So this is a very simple project on how to generate random password. In this tutorial, we're going to build a dice rolling simulator program. So what this is going to do is that it's just going to ask everyone to roll a dice. Then once we say yes, it's actually going to like simulate rolling a dice and it's going to print out two different numbers ranging from one to six. And it's also going to show us like a drawing of those numbers. So let me show you what these actually looks like before we get into coding. So this is the program, right. And it says roll dice. If I say yes, you can see that it says dice rolled up four and three. And it shows me the dice four and three. If I say yes, again, it wrote five or one, it shows me five or one, say yes, again, erode two or four, it showed me the dice drawing of two or four. So let's get straight into this. First of all, let's make this a little bit less. Now the first thing that we actually want to do is just to, you know, let's walk through the steps we're going to use random. So we're going to have to import random. Then once we import random, we're gonna define a function to roll the dice. So once we define that function to roll the dice, the next thing we want to do is to like have a kind of like a dictionary. So create a dictionary, a dictionary that basically will, will have the drawings of the dice. So this is dictionary is going to hold like all the drawings of the dice and everything we need. And then we're just going to get into using a while loop asking the user for what, you know, if they want to continue on all of that, let's just collapse this and get straight into it. So as I said, the first thing we want to do is to import random. Once we have random imported, then we're going to have a function named roll dice. And in this function. So what we want to do in here is that we want to ask the user so we can say row equals input. And then we'll say something like roll dice, yes or no. So let's just deactivate this real quick. So once we say roll dice, yes or no, we are less likely changes to yes or no. We're going to ask these are two inputs, if it wants to roll the dice. So we're going to say while row, the lower is equals to yes, the lower. So the reason why I do this road or lower and yes, the lower is because if the user inputs, yes, with all cap letters, or small letters, or a mixture of cap letters and small letters, is still going to see it as the user saying yes. So we're just going to say dice one is equals to random dot random dot rand int. So the random integer between one and six, so it's going to generate a random integer between one and six. So we said dice to generate another random integer between one and six also. So once it generates that, what we're going to do is print dice road. And then we're just going to say this and this. So this is going to hold let's say two and three, four and five, whatever was wrote, then let's format it the format. And let's just format it to have dice one and dice two. So once we have this, what we can just do, we can then ask the user if he wants to roll again. So say roll equals input. Then now instead of saying roll dice, we just roll again. So yes, or no. And then we're going to ask the user for that. So what we just want to do now is to run this particular function. So this should work perfectly. Let's see. So let's quit this tab and run it again. So yes, we want to roll a dice. So it says six and four road. Yes, six and two, six, one quite lucky, three and six. One on one. So you can see that that is working. The next thing on the final thing we want to add is to just add the drawings. So we want to actually have like images or drawings of the particular number that has been rolled. So to do this, what we're going to do is to come, we're actually going to come all the way up here. So what we're going to do is to just say I'm going to paste a black a block of code. Now this code is going to have all the drawings. So what I'm going to do is to come in here and just paste. So as you can see, this is like, it just is basically a dictionary, right? It has a key and the value as like this topu, but in each of the topu as like values that forms this square type shape that has each of the values for drawing 12345 and six. So you can just take you know, all of this, right? Yeah, that is how that looks like. So once you know, you have this, everything is basically done, you just need to know the name of this particular dictionary. So once you know the name of that dictionary, next thing you want to do is to then go down into the code where we are printing the values that were wrote. So down here, we just want to print. Let's see, let's leave a space, first of all, something like this. And let's just say dot join. Dice drawing. The one that has index key, not index this time around key of dice one, we did the same thing for dice two, unless you what it gives us. So this should work perfectly. So yes, we want to roll. So you see it says five and four, it prints five and four, one roll again, five on one, it prints five on one, one roll again, one and six, it prints one and six. Now let's say no, it's cut out or it breaks out of that program. So that is how to basically build a dice rolling system or dice rolling simulator. In this tutorial, we are going to be building a site connectivity checker. So what this is going to do is that we're going to give it a URL or a particular link, and it's going to check the main the status of that site, basically. So if the site is up and running, if you can access that site, or if the site is down, it's going to give us an error. So once we give it the link or the URL is going to give us a response. If the site is up and running, and everything is working, it's going to give us a response of 200. And some other response if there's an error or something. So let's just get straight into this. We need to import a library that we're going to use. And this library is called URL lib. So this should be installed when you have Python installed, it should be pre installed its Python already. But if it's not installed, you can just type pip install URL lib. And that should install it for you. So let's go ahead and write the steps of what we're going to do. So this is quite easy and straightforward. The first thing is just to import URL lib. Once we have that imported, we're going to use a particular subset of that URL lib called request. So we're going to use URL lib dot request. Yeah, to get the data from the URL, that's exactly what we want to do. Then once we do that, the next thing we want to do just to write a function of function that takes a URL and then returns a response. So this is all we want to do is disable that. So this is all we want to do and it should be very straightforward. It's actually very easy to, you know, to code, because the library already has what we wanted to do for us. So let's just follow these steps. So let's import URL lib. So this URL lib that we're importing, we're not just using it directly. As I said, we're going to use dot request. So we're just going to import URL lib dot request. Let's import it as URL lib. So that when we are using it, we don't need to write URL lib dot request, we just say URL lib. And what we want to do now is to have a function called main. So this function, let's say it's collect a URL. So in here, we can just print something like this is a site connectivity. Checkup program. And then we can just print to input the URL of the site. But actually, we I think we even want to, you know, tell the user to input the URL before running this particular command. So what we want to do is to come here. I want to take all of this year and put it here instead. So what this is going to do is that is going to print this until the user to input the URL of the site. So what we can just do is that we can just say URL input URL is equals to input. And then we can just have this right here. So input the URL of the site you want to check. And this is going to input the URL for us. This is going to collect the URL for us, then what we're going to do now is we can say dev main, what we can now do is, since we already know we have the URL, we're going to take the URL, let's just say, URL equals URL, that doesn't really make any difference, since we already have URL being sent in here. So let's just leave that like that. And what we're just going to do now, we can just do something like print, check in connectivity. And then we can say URL leave dot open dot URL open. So we want to open up this URL. But then want to store whatever is gotten here in a response. So we'll store it in a response variable. And this is basically all we need. And we can just print something like let's say, connected to URL successfully. That is all we need. But then we want to show the response like is your response of 200 is an error. So let's just say print the response code was response dot get code. So this dot get code is going to allow us to get the code or the response code basically. And as I said, it means that it got it successfully, was able to use that site successfully. So this is basically all we need right now. But the only thing I see that we need to change is that we need to have this particular function above all of this. So we need to write the function first. And this is because once the user inputs this URL, right, the next thing we want to do is to call this URL on diet, know is to call this function on that is using the URL that the user wrote. But in Python, everything is step by step. So we can call a function that is below our code. So imagine I call the function main year, that's impossible. As you can see, it gives us an error that it can recognize that particular function. And this is because Python looks up not down. So once I call this function, it looks for this function from the code above it, since it doesn't find that it doesn't see that as a function in this code, even though we still have the function right here, but it doesn't see it. So what we need to do is to make sure that the function is above the code or above where we are calling it from, then that will work. So what we just want to do, let's remove this from here, we can take all of this function, we can cut it out, then right here after importing, we can just paste that now everything should be working successfully. So if I now say let's say I run, so let's say I run this and I say, main, and I give it the input URL that the user input this right here. So right, I'm just going to say input URL. So once I give it this now, everything should work successfully, because it's going to go up and look for this main your this main function is going to give you this input URL, which the user entered. And then he's going to, you know, open it, save it in the response and print the response code. So that is all we need. And as you can see, right here, it didn't give us that error that he can't find the function that is because the function now is above it. So that is also a good tip to know in Python. So let's save this file. Let's run it. So it says is a site connectivity checker program, input the URL of the site you want to check. So let's just check it. I said www.google.com. So you see it says checking connectivity connected to google.com successfully, the response was 200. Now 200 means it was able to access that URL or that link. Let's run it again. Let's say, let me check my site. So my site is up and running. Let's see if it's also going to give us 200. Could it tell me.com. As you can see, it says connected successfully, the response was 200. So that particular one works successfully. So everything we did here is very easy and very straightforward. We just use the library and we just allow these are to input it and input the link and then we give the user a response. So I hope you understood what we did in this tutorial. In this tutorial, we're going to be building a currency converter program. This is very easy and very straightforward. What we just need to do is to first of all, have a function that is called main. And this function, we're just going to, you know, say this is a program that converts, let's say us dollars to, you know, great Britain's pounds. And then we're going to collect the say we're going to ask a user for the amount of dollars they want to convert, then we're going to run a function named converts to pounds, then we're going to show the user the answer. And under that we are going to also going to have to have another function, we're actually going to use a lambda function to, you know, have this particular converter and I'm going to show you what we're going to do. So let's get straight to it. So we're going to say death main. I want to do is print this program converts us dollars to pounds sterling. And let's just have another print so that there will be some spacing. So print and dollars will be equals to input, enter amount in dollars. And we have to evaluate this. So we have to wrap it with the evaluate. And once we do that, we're going to say pounds will be equals to convert to pounds, we're going to give it dollars. So once we have that, we're going to print that is and let's say pounds. So what we're going to do now is that is we just want to print the equivalent in pounds. So that is pounds, I'm going to have the comma and say pounds in here. So this should do the work for us. But as you can see, it says I doesn't see any function named convert to pounds. So all I'm just going to do down here is to come here and create a new function named convert to pounds. Because the lambda dollars, so dollars multiplied by so we need to check the exchange rate. So if we come to Google, you can see that the current exchange rate is no point 82 pounds sterling. So we're going to say multiplied by no point 82. And that should actually do the work for us. So now if we call main, everything should work. Well, right here, we need to have lambda. So now everything is working perfectly. If we run this, this should actually work. Now, let's save it and see input the amount in dollars, let's say $500. So it says convert to pounds is not defined. So this is because right here, there is no n. So that should work now. Now let's run it again, and say $500. So you can see it says that it's 410 pounds, let's run it and let's say something like $750, 615 pounds, let's come back and you know, check that 750. So you can see 614.14. You know, I think he wrapped it up to, you know, 615 pounds. So that is how to build a very easy and simple currency converter. Of course, if you want to like scale this or like actually build a big application from these, what you need to do is to like, probably have an API that gets all the rate, like this type of rate, then you should do something like you're going to ask the user what the two different currencies you want to convert to, then when you have all of that, you know, what function to call, you know, what rates to use and all of that. But for now, this is just a basic, you know, way of doing this type of application. In this tutorial, we're going to be building a very simple program that tells if a particular year is a leap year or not. Now to do this is quite easy and straightforward. What we just need to do is to have a new function. And this is going to be something like is leap year. And it's going to take your parameter. And it's just going to say if year percentage, the percentage sign should be, yeah, if your percentage for equals to zero, that means if the remainder of the year divided by four is zero, then we're going to say, it should be a leap year, but we also have to have another condition. But before we have that condition, let's first have our else statement. For now, let's pass and say else print not leap year. So basically, what this is saying is that if your percentage for which is the remainder of four is not equal to zero, then is not a leap year. So yeah, when we say pass, what we want to do is just have another condition. So we're going to say if your mod 100 is equals to zero, then we're going to do something else. Just print leap year. So right here, we just want to print leap year, let's change this real quick. So this is a leap year, then right here where we pass, what we want to do is have another nested condition and just say if yeah, mod 400 is equals to zero, then that should be a leap year. So we're just going to print leap year. Else, it's not a leap year. So this is a very basic program that does this. So you can see just this function alone should be able to, you know, do the work. What we can just do now is to run this. So say is leap year. And let's give you something like 2000. So let's quickly go over what is actually going to do. So this is saying if your mod four is equals to zero, then we're going to check if your mod 100 is equals to zero. And we're also going to have to check again, if your mod 400 is equals to zero, then is a leap year. So but initially, if it's not even equals to zero, is not a leap year, right here. Also, if yeah, mod 100 is not equals to zero, it is a leap year. But if it's equals to zero, and then mod 400 is equals to zero, also, then it's a leap year. Else, it's not a leap year. So if you actually do the calculations manually, you'll see that it adds up. So 2000 was a leap year, let's save it and see what it says. So as you can see, it says leap year, what we just want to do is to come in here. So right here, I have a list of leap years 2000 2004. So leap year is basically every four years, right. So what we can just do is, you know, change this and say 2024. And that should print leap year 2020 also should print leap year. Right. But let's try for something that is not a leap year, let's say 2013. As you can see is not a leap year, let's say 2051. That is not a leap year. So that is the way to build a program that tells you the year is a leap year or not. In this tutorial, I'm going to show you how to build a simple word dictionary using Python. So this is going to be a program where we're going to have a basic dictionary that has a key value of a word and the definition of that word, then we're going to be able to ask the user to input a word. And then from the dictionary that we have, we are going to get the meaning or the definition of that word. So let me walk you through the steps of what we're going to do. So first of all, we're going to have a Python dictionary that has a key value pair that represents a word and its definition. So once we have that, the next thing we're going to do is to collect input from the user. So this input is going to be is the word is a word basically. And then we're going to check if the word is in the dictionary and print the definition. So this is the basic steps that you're going to take. Let's just get started with it. So we cancel of that. The first thing, let's just have a function named main. And in this function, we're going to have a word dictionary. So let's name this word dictionary. So we're actually using a Python dictionary, right to store all the values. So what we're going to do is to say equals two. And let's say we have a word named I and we say a way of greeting. Let's just say we have another word that says ice. And let's say an organ for sin. And yeah, let's just have those two words basically. And we okay, let's add one more just to give it a say F. And let's say a planet in space. Cool. So we have this, let's make sure we have our comma right after every single key value pair. So once we have these, the next thing we want to do is to collect the word from the user. So we'll say word is equals to input, enter a word. And we can say, let's say something like we can just say if the word is blank, we want to break, or we can just go straight to it. So let's just say something like if word is equals to blank, then we can either tell the user to input it again, or let's just break, we can do that. And we say if word in word dictionary. So that means if this word is inside this word dictionary, then what we want to do is to print the word, then we're going to print the word definition. So I'm just gonna say word dictionary of that word. So this is going to do it for us. But this break, basically, when we say break, that means we are breaking out of a loop. So the reason why I put this break here is because we're actually going to write a while loop here so that the user can keep asking for a word till he doesn't want to ask for it again. So let's say while true. So while this is true, all of this should be under this and this should be in small letters. So this should now work perfectly. So let's run this. Let's see what it does. So entire what event I so it says I a way of greeting, if winter F, F, a planet in space, winter ice, ice and organ for scene. I see that once I enter nothing, and I click Enter, it breaks out of the program. So this is how you can be the basic, you know, word dictionary. But you would have already seen a problem with this, there is no way we can actually write all the words in English and their definition in just a basic Python dictionary. So is it that let's say you have a file an external file that you can import that has all the texts and you know, even the synonyms and the definition, or you can just use a Python library. So there, there is a Python library that someone has already worked on that you can just install on your computer. And, you know, that has all this data that you need. And you can just use that in your program. So to take this a little bit further, I show you how to actually view the working dictionary that you can actually use, we're going to use a dictionary library named pi dictionary. So what I'm going to do now, I'm actually going to clear all of this up. Okay, no, I'm not going to clear this up. But I'm going to open a new terminal. So let's come here and click New Terminal. When we install pi dictionary. So if you're on a mark type PIP three, if you're on a Windows, just type PIP. So install pi dictionary. So I already have it installed. So he's saying requirement already satisfied. But for you, it should go ahead and install that. So let's close up this terminal. Now that we know we have that the first thing we want to do is to import this pi dictionary. So I'm going to scroll up here, I'm going to say from pi dictionary, import pi dictionary. So once I have this, I'm going to define an instance of this pi dictionary. So I'm going to say dictionary is equals to pi dictionary with the parentheses. And once we have that, what we can just do right here, so we're going to say, we don't even need all of this. We don't need to put in a function or more, what we can just do is to say, let's collect a word from a user. So let's say, or let's just first test this and see what it gives us. So let's say print dictionary. That's meaning let's say something like ice. Once we run this, you can see that it prints this right here. And it says noun, the organ of sight, good this, it basically gives you different definitions. So different noun definitions of ice, right? Yeah, you can also see that gives you different definitions, different verb definitions. That's what that can do. And you can do a bunch of stuff, you can translate a word from, you know, one, one word, one language to another, it can give you synonyms, antonyms, and more. So you can explore that more if you want to see. But for now, let's just stick with this. So what we can just do now is to ask the user for what he wants to import. So what he wants to get the definition of, so we say input, enter your word, then we can say, print dictionary dot meaning of word, let's see this. Now let's say ice again. And now we can input our word, I will get the meaning of that word. So we can also, you know, have a while loop. Wow, true. And all of this should be on diet. And once we have that is going to keep looping. But why do we want to break it? So what we can do is if word is equals to blank, then we want to break out of it. So that's all we need, but then just print the meaning of word. So if his blank is going to break out of it before he even runs this, so we're cool. Now let's try to run this and see. So let's have another word like, let's say indentation. And as you can see, it gives me the meaning. And that's what we need. Now let's run it again and just not input anything, it breaks out of it. So you can see that the library is quite efficient, it has everything you already need. So you don't need to start writing all the words in English and the definitions because that's going to take a long time for the two results. So another thing we can do is to actually give this library like a bunch of words, and it's going to give you the meaning of those words, in let's say, a list or even a dictionary format. So let me show you what I'm talking about. So we can remove this. And what we can do is we're initializing this, we can just give it the words immediately. So let's say we give it ice. And we give it indentation. And let's say we give it head. So we give you all of these words, what we can just do now is to print dictionary dot dot print meanings. So this is going to print the meaning of everything for us. And this is going to print once we run. So as you can see, it gets all the meaning. So we say eyes, it shows us the meaning in nouns, with as different meanings, and also for verbs, then for the next one indentation, and for the next one, it gives us everything we need. But let's say as you can see, this is just a plain text, and there's no way we can actually use this, like in our code. But what we can just do is you allow it to return us the definition, but in a dictionary format in a Python dictionary format, so then we can, you know, have key value pairs that we can actually use or print in our program. So instead of print meanings, what we just want to say is get a minute. So once I save this and run it, you're going to see now that we have this for in a Python dictionary format. So exactly the same thing. But now we can use this anyhow we want since it's a dictionary format and Python understand dictionaries. So we can, you know, just get let's say we just want to get just this definition or just this definition, we can actually get it because it is in a recognizable data structure in Python. So that is the best way to go about it if you have multiple words that you want to print. So that is how to build a simple dictionary in Python, a simple word dictionary in Python. I hope you understand everything we did to this point. We're going to be taking our Python knowledge and using it to build a simple game of rock paper scissors. But the first thing we want to do is to import random. So we're just importing this down because we're going to use it later. And you want to have a list that contains the options. So the options are rock paper and scissors. And I'm going to ask for the user input. And user input is going to be input choose rock paper scissors. And the computer input is going to be randomly chosen from one of these three lists. So I'm gonna say computer. Let's go input random dot choice options. And in here, we want to change something or want to add something, we're going to say rock paper scissors or exit. So if the user types rock paper scissors is going to keep playing the game every times exit is just going to opt out of the game and want to have exit as a Boolean, which is going to be false. So this exit is we're going to have like a while loop, we're going to say while exit is false, then want to keep playing the game. But if the user then types exit, we're going to change exit to true. So that means he wants to opt out of the game. So actually, what we're going to do, we're going to actually have exit on top. And then all of these should be in like a while loop. So while exit is equals to false equals to false, then we want to keep doing all of these. So this should have an indentation. So while exit is equals to false, let's just say, now, we're going to say if user input is equals to exit, then we're going to print game ended. And they were going to set exit equals to true. So now that exit is set into true, if the user input exit, this whole program is just going to stop. But if user doesn't input exit, and let's say the user says if user input is equals to rock. So if user input is equals to rock, then we're going to check if computer input input is equals to rock also. So if user inputs rock and computer inputs rock, then we're going to print your input is rock. And we're also going to print computer input is rock. And it's a tie. So if user inputs rock, computer inputs rock, that is a tie. And let's have an else if statement and say if computer inputs is equals to paper, then we're going to print these three things also, but we're going to change some stuff. So we're going to print your input is your input is rock, but computer input is paper. And obviously, the computer wins. So when the computer wins, we want to add one point to the score of a computer. So what we are trying to do is to come up here and have the user point. And then we want to have computer point equals to zero. So what we're going to do when the computer wins, we're going to say computer point should be point and then computer point plus equals one by increasing the computer points by one. And we're going to do the same thing again by saying the computer now input scissors. Then we want to say your input is rock the computer input scissors. And then we're going to say user point plus equals one. So this is the basic logic of what we're going to use to build this program. And then we're going to continue by saying yeah, we're gonna have an else if for this time around, it should be if the user input is different. So let's say the user input is equals to like paper. Then we're going to do all of this. We're just going to copy this, paste it in there. And then we're going to check if computer input is rock. So you input paper, computer input rock, then you win. When you win, we increase your score by one. And then computer inputs is paper. And then your input is also paper. Then we're going to say it's a tie. So when it's a tie, we don't input, we don't increase any score. So we're going to remove this. And now computer input is paper. So we're going to say your input is paper. Computer input is scissors. Then computer wins. So we improve computers points by that. We're going to do the same thing again, but this time around for when user input scissors. So now if the computer input rock, we're going to say your input is scissors. Computer input rock, computer wins. So we're increasing computer points by one. And we're going to do the same thing. Your input is scissors. Computer input is paper. And then we're going to say is you win. User point plus equals one. And right here, your input scissors is a tie. And one is a tie. As you know, we're not going to increase it by anything. So we're just going to remove that says a tie. So we can also, you know, have some verification to say like, then let's say else we can say else. But since this is not here, we can just have a new statement and order else is statement by saying if user input is not equals to rock or user input is not equals to paper or user input is not equals to scissors, then what we want to do is to print invalid input. So everything is working perfectly now or should work perfectly. Very simple and basic program. Let's save this and come into our terminal. I'm just going to say Python three, Python app dot py. So what I'm doing is just running this Python app where we built the program. So Python three, Python app dot py. So this is the Python app dot py where we built this. And once I click enter, it tells me to choose. So I choose rock. It says your input is wrong. The computer input scissors, you win. And we can keep going and say, um, let me just paper your input is paper. Computer input paper is a tie. And if I say exit, it's just going to stop that. And then you're just going to opt out of that. So, you know, it does all of that. But one thing it doesn't do is that it doesn't print the point. So we are meant to like show it like your point is this, your point is that. So let's say if the user input exit, we'll print game ended and then let's just print the point. So let's say you want a point total score of, then we're going to use concatenation to add up, add that together. And let's just say user point, add that and say, and the computer total score is, let's add the computer score. So once we save this now, I'll come back here and run that again. So let's say paper and let's say rock. So I won. That means I have one point is a tie. No point. So it's one zero now. And let me say paper again. It's a tie again. I'll say paper again. Computer wins. So it should be one one. I'll say rock, rock. I want to one rock is a tie. So now if I print exit, there's the game ended. And then it gives us an error of not able to concatenate integer. So what we just need to do is to come here and convert that into string before concatenating them. We're going to do the same thing here. Paste that. Come back in here, run that again. Now let's just say rock, rock, rock, rock. Let's say exit. And he says you want a total point of three and the computer one total score of one. So that works successfully. And that is how we can build a simple, you know, console game or terminal game of rock, paper, scissors. Hi, guys, we're going to be building a face detection program using Python. So the requirement for these is that you have OpenCV installed. So to install these, you just need to come here and type p install OpenCV Python. So this command line is going to install OpenCV onto your computer. So having this done, I already have it installed. So I don't need to do that again. And then the next thing you need to have is this OpenCV XML file. Now this file is pre written. And then once we use it in our Python code, it will make it far more easier for us to be able to detect faces using Python. So and then the only thing you just need to have next is the image you want to detect. So you have an image which will which the program will detect the faces and draw like a rectangle around the faces it detects. So right here, I'm just gonna go into my GitHub. And then from my GitHub, I can just get maybe my profile image or something. And then, yeah. So open this a new tab. And then I can just drag this into that. Yeah, and I can rename this to be something like image.jpg or test.jpg. Let's name it to be test. So now we have this, then this face detection dot py is a blank file. I'm just going to open that up in my VS code right here. My VS code you see that I have that file opened up. So right here, the first thing we need to do is to say import CV to now this command, this line, line of code is going to import the open CV which we installed earlier. And then we need to load the cascade. Now the cascade is this XML file, which we have here. And then I'm going to link this XML file in my GitHub. So I'm going to drop a link in the description below where you can get this file. So now let's just load that I can say face underscore cascade. And then that can be because of CV to that cascade classifier. And then let's load it up. So let's just make sure we get experience correctly. h a r cascade to write a cascade underscore front tell face. Let's get default dot xml. Let's check that h a r cascade underscore front tell face underscore default dot xml. So that is correct. And then what we just want to do is to import the image also so can do IMG is the image want to test to CV to that I am read. And then what is the name of that image tester jpg. So we can say test the jpg. And now that we have that we need to convert it into a grayscale. So the type of color in which this can read is a grayscale color, and the image is not grayscale. So any major user input, we just want to first of all convert it to a grayscale color. So we can say gray can be equals to CV to the CVT color. And then convert IMG into CV to that color on the score. Let's say BGR. Yeah, to gray, something like yeah, this BGR to gray. So that's what we want to convert it to. Now that we've converted it to that color, you just want to detect the faces. So we'll say faces can now be close to face cascade. That's detect multiscale. And then gray, 1.1, comma four. So this is just what we're using to detect the faces. Now, once we've detected that there's a face in this picture, we just want to draw a rectangle around that face. So we use a for loop as a for x, y, w, h, same faces. So CV to the rectangle. Yeah, then IMG, we'll say x comma y, and then comma x plus w, comma y plus h. And then outside that, we put under comma, and say two to five comma zero, comma zero, like this. And then outside that, we put under comma and just say two. So this is just to draw a rectangle around those faces. And now let's just display the output. So we can say CV to that I am show. Now this is just going to show us the image with the faces detected. And a rectangle drawn around the faces. Now we can say CV to that weight key. That means if we press a key, it should stop showing. So you're going to see that in a minute. So like this, yeah. So now let's just add one more line and say CV to those I am right. And then we can say face detected the jpg. And then we can give it IMG. So now we can save these and come here and test that. So we can say Python face underscore detection. So as you can see, it shows the image right here with a rectangle all around the face. So that is how to just build a simple face detection program using Python. We're going to be building a Python program, which is going to send good morning text messages to a particular mobile number every day or every morning. So we're going to give it a particular time in the morning, maybe like 6am or 7am to send that text and is automatically going to do it by itself. So for this program, we need to Python libraries. These libraries are text builds, and schedule now text builds is the library that is going to be handling sending of the messages, or schedule is the library that's going to be handling when we want this script or this message to be executed. So let me up over to my browser right here, I have the schedule library opened on pypi. So as you can see, it's pretty straightforward and easy, you don't need to install schedule. And then I'm going to get back to this in a second. So first of all, let's import schedule. I'm just going to bring up our terminal right here. paste that. So I have scheduling installed already. So it should tell me something like requirement already satisfied. But for you, you should go ahead and install that. So let's close this. So now that we actually do installed, let me talk about the other library which we're going to be using. So let me go to the website, text built dot com. Now this is like a website, they, they have this platform which allows you to for SMS marketing for various things right there. But they also have an API, which developers can use to send text messages. So if you use Python, Ruby, Node JS, JavaScript, there are various languages right here. For this video, we're focusing on Python. So as you can see, the only thing we need to access the API is just the request library. So that was in any time, let's pop up our terminal. And then we're just going to type peep, install requests. So this is just going to install requests on our machine. So I have it installed, it says is requirement already satisfied. So now that we have all of these, let's just get started with coding. So as you can see, this is the basic code to just send a text message. So what we just need is the URL, which they've given us here. And the phone number, the message and the key. So as you can see, we're posting a particular, some particular data to this URL. So this key, they have this demo key, which is text built. So that key allows you to send message for free, but once a day. So if you want to have unlimited access, then you have to go for your paid plan. But for this video, I'm just showing you how to use this, we're going to be sticking with this text belt key. So let's go back to our code. So the phone number in which we're going to be sending this message is my personal phone number. So I have it stored right here in this credentials or pwifi. I have my phone number stored as a variable right there, just for security reasons. So I don't show it here. The first thing I want to do is to import the mobile number source it from credentials, imports mobile number. So now that I have that imported, I'm just gonna dive straight into the code. So I'll say import requests. So now that requests is the library we're going to be using to send data to text builds. So now we're just going to have our function is going to basically send message. And we don't want to give it any parameter, we don't need to. And then we can just have a simple variable named res, which should be close to requests, dot post. Then we can see HTTP. So now this is the text built website in which was sending or posting our data to say text built dot com slash text. So now we're just gonna say the phone number, which is phone should be this mobile number which we imported. So say it's mobile number. And then the next thing we need to give it is the message. So we can just say the message is a good morning. That's the message. And then the key, as I explained earlier, why isn't the demo key, the free key, so the key is text built. Now we have all this setup, let's make sure we put a comma right here. We have all these. And then right here, we just want to print res dot JSON. So we want to print the result as in a JSON format, basically. So now we have these codes done. So this code on its own, if I run it, it's just gonna execute this function and then send me this message a good morning to my mobile number. But that's not what we want to do in this video. That's not the main purpose. The main purpose is to show you how to schedule this particular function. So let's quickly go back to the schedule page right here. Now you can see that is pretty easy and straightforward to use these, all we just need to do is to import schedule and time. And then the function which we want to say do, which we already have right here. And then we just need to know the time we want to schedule it to. So that's very easy. Now, let's import schedule. And then let's import time. So now we have these imported. And then the next thing we just need to do down below our function, we can just say schedule. So want to schedule it to be for every morning. So say dot every day on say dot day, you know, say dot, so day dot at. So want to schedule it for every morning at a particular time. So right here, we should have this curly braces, that's because it's like a method, like a function which we are using. So we're saying schedule dot day, that's every day dot at. So right here, this art is the time in the day we want to schedule it for. So let's say 6am, so 06. So we don't write in right here, what we do is just write it in the 24 hour clock. So if it's 6pm, we need to put these at 18 006am 06. So now that we have that we just say dot do, then right here, we passing the function which we want to run. So say send message. So now I would like to run this now. But if I run this now, obviously, this is gonna send me a message at 6am tomorrow. So first of all, let's comment this out. And then let's run these like every 10 seconds. So it's gonna do right now. So we can just simply say, just for the testing, we can say should do that every 10 seconds. That's do and obviously we want to do send message. So that's the code to do that. So for every 10 seconds, basically do this function. And then we must not forget to add our while loop so it continues the loop. So every day, every minute, every second continues to loop. So say while true. Should do dot run. pending. Yeah, that's it. And then time, let's give it a sleep. Just one one is fine. So now this is ready. Let's quickly go to recap on what we did. So we imported the phone number, the request schedule and time, then we add the function which does everything. And then right here, we just shared dude, when this function should be executed. And then we made sure we add the loop. So now let's run this and test it out. So let me pop up this time now. Right here, you can see that it is running. So we should give it like 10 seconds, because right here, we said 10 seconds. So in 10 seconds, it should have executed. So right here, it says success, false arrow out of quota quota remaining zero. Now this error just saying that this text belt key right here has been used for the day. So I use this one, I was testing it today. So that's basically how to do that. As you can see, it's running every 10 seconds, every 10 seconds. As I said, this key can only use it once a day. So obviously, I have used it today, I guess that's why. But again, if we make sure we come here, text built, okay, so it is text built, and we wrote text built. So I should love that. Done already, because I have used it today. But let's see. So it might work, it might not work 5050 chance. Let's see. Let's go. Maybe I should quit this quit, and then run again. So now fingers crossed. Let's give it 10 seconds. 1234. Okay. Do eliminate. So still the same things test text are temporarily disabled. So she showed us the same thing that temporarily they have disabled test text. So it's running every 10 seconds. Yeah, that is done. So there are other libraries instead of unit text, but you can use Twilio, you can use basically plenty of stuffs. But I just showed you how to use this schedule library. That was the main purpose of this video to schedule a task. Now you can see is doing every 10 seconds. Anyhow, you want it. Hey, guys, what's up, we're going to be talking about web scraping with Python. So web scraping is basically just getting or extracting data from a website. So when we say web scraping, web stands for website scraping stands for you know, extracting or getting some information from that website. So that's basically the concept of web scraping. So this can come in and do sometimes is popularly used in Python. And I'm going to show you how to do that in this video. So I have my website here could return me my blog website. And what I want to do is I want to scrape all the names of blog posts I have on my website, I can scrape everything, or I can just only get the first name or anything I want to get. So our web scraping works is that we're going to send a request from our code, we're going to send a request to that URL, which we want to scrape. And then we're going to get a response back, which the data would need. So before we get started, we need to Python libraries, these libraries are requests, and beautiful soup. Now request is used for sending requests. And beautiful soup is used for featuring the data we need specifically. So let's go ahead and install this library. So say beep, install ps4, which is beautiful soup, I will say beep, install requests. So as you can see, the board gives me requirement already satisfied that because I already have it installed. So now let's just go into our Python shell. Right here, we just need to import requests. And then after that, we need to import beautiful soup. So say from bs for imports, beautiful soup. So now that we have those two imported, this URL, which we want to send a request to, we need to specify it in a variable, say URL equals two. So now we have the URL want to send a request to. So let's go ahead and send the request. So say r equals to request dot gets to this URL. So now we've sent a request to that URL, we put R on it, enter, it is response 200. Now when it says 200 means the request was sent successfully, I'm getting a response. That means everything is okay. But we have another one or any other number, it means an error. So now that we know that everything is good, we'll just use beautiful soup to get the data we need. So first of all, we have to do soup equals to beautiful soup, open brackets, add that content, comma, we'll put lxml to pass it well. And we enter. So now this has passed what we need. What we want to do now is to get the name of this. How will we know this? So now we need to know the HTML tag this belongs in z it's in an h1 tag is in a p tag is in a div tag. First to do this, we'll make sure we're on what we need. We right click on it, scroll down and hit inspect. So now you can see that it is on that title, which I need. And as you can see, it's in an h2 tag with a class of post title. So let's tell our Python code that does what we are looking for. So let's say title should be equals to soup. Now this is the soup dot find underscore or find or find the one with an h2 tag, which has a class of post title, post title. Now let's close this. Now, let me just print title. You can see, I have a list of HTML code. The first one is also deploy a Django project with Roku. The second one is best way to get started with Django. The third one is how to create a Bitcoin wallet. And on and on and on. But all these are just HTML codes. Now I can just print only the text, I don't want to print them with the a tag or the h2 tag. I just want only the text, I can just say title dot get text. So now it says there's an attribute error. So anytime we are using the get text, we must make sure that we're only getting one. So anytime we're using that dot get text, we cannot easy for a list, we can only use it for when we are getting, let's say only the number nine or the number four or the first one. So now we can just say title. Let's get the first one, title zero, dot get text. Now you see it says how to deploy a Django project to Roku, it gives me only the text, but we still have this n and this, that's because we didn't put it in a variable. Now let's say we add it in a variable and say title one equals to title zero, dot get text. Now when I print title one, you can now see that it just gave me what I need out to deploy a Django project to Roku, which is what we have right here. But right here, you can see that we had an error, it was that when we said title, the get text, when I said you can only use it for one. Now we have another way which can use which is a for loop. So we can do something like for see in side to get text or team title, we can do something like print t dot get text. So as you can see, using a for loop, it automatically gives us only the text of every single thing. That's because we used a for loop, you can see only the text. Now we don't have any other HTML code with it. It gives us a list of all of it. But now I'm sure you might be having a question that I thought we only get in the first one. And then we add only the HTML code for this first one. Then why is it giving us a list of everything? So the reason why when we told HTML, we want this code, and instead of giving us only this code, it gave us everything is because each of these is inside the same tag. So now you can see h2 class post title, if I come here, I'll come to the second one, you'll see is also in h2 with a class of post title. But do the same with third one is in h2 with a class of both title. So that's what it does is just going to get a list of everything correlating to the data you gave it to find. In this tutorial, I'm going to show you how to resize an image using Python. To do this, we're going to use a particular library called pillow. So you need to make sure you have pillow installed. But before we even get into coding, let's quickly write the steps that we're going to take to do this. So first, we're going to have to install pillow. If you haven't, then we're going to import pillow, of course. After importing pillow, what we just need to do is to open up the image, the image we want to resize is in Python. So we use a particular code to open up that image, then what we can just do, let's say we want to print the size, the current size of that image, so the user knows the current size. Then once we print the current size, we want to specify the size we want to change it to change it to then once we specify that we just save, save the new resized image. So this is literally all we need to do is pretty straightforward and pretty quick. So first of all, let's open up a terminal to install pillow. So what you need to do is to type in three. And as I always say, if you're on a Windows, just type in if you're on the Mac, type in three, install pillow and knows that I use capsulator. Yeah, it has to be capsulator for P. Once I hit enter, I already have it installed. So it says requirement already satisfied. But for you, it should just go ahead and install that. So let's close that terminal, we can leave those comments there. So we'll follow it. So to import pillow, since this is done, I just hit done. Next thing we want to do is to import pillow that is easy. What we just need to do is to say from P I L, import image. So P I L alone is pillow does what we've imported. But for this particular thing we want to do for the resizing, we need this image. So that's why we're importing image from pillow, we don't need the whole module, we just need this image. So once we have that, let's update this and say done. Next thing we want to do is open the image we want to resize. So to open the image, we're going to use image to open. So let's say image is equals to image dot open. So I'm having a new variable named image. This is where I'm going to store the opened image. And I'm using this image module, and I'm saying image does open. And then we're going to specify the name of the picture that we want to open. So right here, I have this picture named code with Tony logo. So I'm just going to copy the whole name. And I'm going to come back in here. And I'm going to paste that in there. So that is going to open up that image and store it in this variable. So that is also done. The next thing we want to do is to print the current size of the image. So to do this, we're just going to say print. And let's do something like f current size. So we can say the image size image, which is this image dot size, that is just going to print the current size for us is that easy. We can actually test this. So let's run it and see. So as you can see, it says 176 to 176. That is the current size. Let's actually test that and see if that is correct. So we come back in here, we right click and click on get info. So let's see right here, as you can see in dimensions, it says that that is one synthesis by one synthesis. So that is pretty accurate. So once we have that done, we know the current size. So now we can know what we want to change it to. So let's see, let's say, resized image. So this resize image is the variable, which we're going to store the new the size of the new image. So we're going to change this image to let's say 500 by 500. So to do this, we're going to say image dot resize. We just want to say, we are going to have two brackets in here, 500 by 500. So this is going to resize the image to 500 by 500. But we are not done this just like specifies what we want to change, but it doesn't actually save it. So to save it, we're going to say resized image dot save. So now we're going to specify the name of the new file. So let's say code with Tommy logo, let's say 500.jpg. So we want to save it as a jpg file. Let's see jpg. Same thing, but let's just leave it like that. So this is actually what we need is just like 123455 lines of code that we need to actually change this. So let's save this file. Let's run it shows us the current size, it doesn't say anything. But if we come back in here, you're going to see that we now have a new picture been saved, you're being created your name code, you told me logo 500, which is actually what we specified right here, code with Tommy logo 500. Now, if we right click it and get the info, the information, you can see now it says the dimension of this image is 500 by 500. So this is how you can use with Python. So there are various ways you can even actually implement this in like a real project. Imagine you have a you can you have a user that wants to, you know, come to your website, and you know, upload an image and change an image to whatever size they want, they can easily do that with using this program. So you can actually let's say build a web app that does that takes an image and tells the user to input the size they want to, you know, change it to, and then you give them the image or let's say you give them a link to the new resized image. So let's actually do something like that. Let's ask the user what they want to put this in a function. And let's see what that does. So we can say def resize image. And this is going to collect is actually going to have two different parameters. So size one, they just say that size two, I guess. And what this is doing is ice collecting the pixel dimensions. So we're going to tap this. But what this is just going to do now, so it's going to open this image, right? Print the current size. And then instead of saying this, we're going to say size one. And size two, that's a two, let's just say, what we can even do right here, we can just do something like, you know, this is concatenation. And we can just say, size one. And then you know, to have that's the name of the image. So now we can call this function. resize image. But to give it the you know, the parameters it needs, instead of just giving it like, you know, if 2200 by you know, 300, what we want to do is to ask the user so we can just say print. No, we want to say size one equals input enter length, enter width. And for size two, we can say enter length, then we're going to call this function using the size one. And size two. So this actually makes it quite more interactive. So now let's see what that gives us. We run this entire wave to let's say I want to change to 2000 by 40, weird dimension, but let's see. So it actually gives us an error, it says string cannot be interpreted as integer, that is right here. So what we need to do is to just make sure that we are changing this input into an integer, because it sees it as a string as default. So we're gonna do this integer, wherever the user inputs want to change it to an integer. So let's save that you can either change it to an integer here, or you can just do the same thing by changing it to an integer right here like this. So that's the same thing, but we already changed it there. So it should work now. Let's run this 2000 by 40. So it gives us an error and says can only concatenate string not integer. So also, we were, you know, dealing with concatenation, you can add us because it sees this as an integer, right? So you can add an integer on a string. So what you need to do now, you need to change this back to a string right here, we were concatenating, and that should solve it. So let's run it again now. And this should work perfectly. 2000 by 40 gives us the current size, right here. And if we come back in here, we're going to see that we have called it to me 2000. We had looking image where we get the info. You can see that we have 2000 by 40. Now, this is how you can resize an image with Python. In this tutorial, I'm going to be showing you how to draw a chart or graph with Python. So this is quite straightforward, because we're going to be using a library called matplotlib. So we first of all have to install the library. And to do this is quite easy. What we just need to do is to open up the terminal and install it like we install all the ones so pip free install matplotlib. So I have installed, of course, it says requirement already satisfied. But for you, it should go ahead and install that if you don't have it installed. So once we have this installed, the next thing we need to do is to just import it. So we're going to import matplotlib dot pi plot. So what we need is dot pi plot lessons, but it as PLT. So we don't need to type this every single time, we just type PLT when we need it. So the first thing we want to do now is to determine the x axis. So in a graph, right, we have the x axis, and we have the y axis, the x axis is the horizontal y axis is the vertical. So we want to determine the points for the x axis. To do this, we can just say x, I'm going to specify that as a list. So let's just say something like 2245. And we are going to do the same thing for the y axis. And let's say something like two also, but then three, six, so that is all right. So what this is this our coordinates. So this is the first coordinate two, two, four by three, and five and six. So these are coordinate are corresponding to themselves. So on the graph, there will be a point where two is equals to two, four corresponds to three and five corresponds to six, I'm going to show you that. And so let's plot the point to plot the point, we're going to say PLT dot plot x comma y. So this is going to plot the point. But then we want to name the x axis, so it's going to have a name. So to do this, we're going to say PLT dot x label. So let's say x axis. We're going to do the same thing for the y axis. So say PLT dot y label. And let's say this is y axis. And what we just need to do is give you a tie to let's say PLC dot tie to is pretty easy and straightforward. So we can just say demo graph. And what we just need to do now is to just show it. So everything has been plotted successfully, we just need to show you by saying PLT dot show. So this is going to show us the graph. And once I click on run, is going to open up, as you can see, it opened up this particular window. And as you can see, right here, we specified, let me quit this real quick, two and two. Okay, I quit that so that quit, let's run that again. So let's make this large, you can see that this has two by two, this has four, and three, and this has five and six, just like what we did here, two by two, four, and three, five, and six. So we can play with that a little bit. And we can even add more points and say something like one, I will say four. Now we can let's say, one, six, and yellow. So let's say one, seven. So let's run that and see what that gives us. So as you can see, it's kind of a weird graph, because that's go and come back. But you can see what I'm talking about, as all the points correspond to themselves in what we gave them right here. So to actually avoid that weird error, what we can just use to remove this one, so we don't go back in descending order. So we just go forward, once I save this, and try to run it again. We should have another pop up. Let's quit this. And then run that again. So as you can see, now we have a normal graph. So that is how to do that. Pretty easy, pretty straightforward. As you can see, everything works successfully, we can actually build like a full blown web application just for this, like, or even build an API just on this, just providing this type of service to a user. So that is the first stuff I'm going to show you in here, we can also do another stuff by like adding two different lines on one graph. So for us to do this, all we just need to do is to say, let's say this is x one, y one. And what we're just going to say is, right here, we say PLT dot plot, we're going to say x one, y one. So this is the first line on the graph, we'll say label, let's label this line one. So what we want to do now is do exactly the same thing again, we're now going to say x two y two, so x two, let's give x two, 12345. Let's just make it a normal linear graph. And we're going to say y two. Let's just say 1234. So that is that I'm going to do now is to plot that line also. So I want to plot that line on the graph. So here, PLT dot plot, I want to plot x two, y two, I want to give this a label of line two. So once we have that, the next thing that we just need to do, since we already plotted the first line, and then we've plotted the second line is now easier because we can just say PLT dot x label to actually plot this. So this PLT is like an instance of this particular, you know, pie plots that we imported just so you know that. So what we need to do now is to come here and say, PLT dot x label x axis, we already have that we already have the y axis, we have the tie to the only thing we want to add is called legend. So I'm going to explain what that is. So let's just say demo graph two lines. So we're going to add legend. And what this legend does is that it shows an indication for the two different lines with different colors. So it's going to tell you what color is what line and what color is the other line. So let's say PLT dot legend. So this is going to show that and I'm going to show you what that is when it shows. So this is what we need. Just ignore this error, because I'm sure like the library hasn't updated or something, but everything is working. Now let's run this and see. So as you can see, we have two different, you know, lines. And this is what I mean by legend, if I make this large, this legend is actually indicating what line is what color. So line one is the blue one. And line two is the orange one. So as you can see, we have your y axis, x axis, demo graph two lines, we can even save this by clicking on this button right here is going to save as an image on your computer. So let's come back in and let's quit this. There are also various things we can still do. For example, we can you know, like have point on each graph, like where we have PLT dot plot. So let's actually remove these two lines, we don't want to plot two, let's just have one. And we don't really need legend since we don't have to. So what we want to do right here now is that we have PLT dot plot, what we can just say, let's remove x one by one, let's just change it to x and y. So we can just say right here is to have color. So I'm going to show you what we're doing, because it's better to show you the image. So let's say the color is green. Line style. Line style is equals to dashed. And we have line width. And let's just see line width is equals to three. We have marker is equals to Oh, we have marker face color. And let's say this is a blue and marker size. Marker size is equals to 12. So we don't let's remove this. So we removed that. And what we just want to do is to come here. What we're just going to do is to say PLT dot y limb. So basically selecting the x and y ranges. So we're going to do one to a PLT dot x limb. And we're going to do one to a also. And then right here, we're just going to have the label which we already have there, we're going to have title. So let's just change this to demograph and let's say customization. So I just customizing what we need. And then let's just say PLT dot show. So once we run this, you'll see the changes. So as you can see, this is all we have, you can see that when we specify this line as blue, if I bring this down a little bit, you can see that that marker face color is blue. And line style is dashed. So as you can see, line style is dashed. And the color of that line is green, the color is green, the face, this right here, face color is blue. So basically, that's what all of that does is just some pretty cool customization that you might want to add to your graph. So let's just go ahead and quit this. So now we've been dealing with the normal graphs, what we want to do is to actually, I want to show you how to draw a bar chart. So to draw a bar chart is also pretty easy, or you just need to do. So they just change this to left. And let's say this is height. And let's give this like 12345. And let's give this like something like 1011 2336, and four. So this is the height of the bars, right in a bar chart. And this is the x coordinates of the left side of the bars. And let's give it label for each of the bars. So we're going to do is to just say, tick label, label is equals to, let's say, one, two, we have to put all of these as strings. So one, two, three, four, and let's say five. And once we have all of this, we can now say plt dot bar. Since we're dealing with a bar chart, so when you give it left, height, tick label, equals tick label. And then we want to say with want to specify the width as no point a less a color. Let's give the color something like blue and orange. So that's gonna do the work for us. And what we just want to do is to we don't need this, we don't need plots, what we need was bar. So now we don't also don't need this, we're just gonna say is the x label, which is x axis, y axis, and let's say demograph bar chart. And let's now show it. So that is all we need. So you can see everything we did here pretty easy. Now once we run this, we should have a bar chart shown. As you can see, beautiful. We have 12345 as the names, x axis, y axis, demograph bar chart, that is how to easily, you know, create a bar chart in Python is very easy. And, you know, very straightforward. You can also do more things like scatter graph, you know, pie chart, and all of that. But I feel like if you really want to go into this, you can also research more on this particular library. But for now, this is how to you know, let's run that again, this is how to build a simple program that, you know, automatically generate graphs, giving some figures.
Info
Channel: freeCodeCamp.org
Views: 702,632
Rating: undefined out of 5
Keywords:
Id: pdy3nh1tn6I
Channel Id: undefined
Length: 191min 7sec (11467 seconds)
Published: Mon Aug 29 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.