20 Beginner Python Projects
Skills:
Research Methods90%Reading ML Papers80%Paper Reproduction70%Prompt Craft60%LLM Foundations50%
Key Takeaways
The video covers 20 beginner Python projects, including email sending, calculator programs, email slicers, binary search, quiz programs, and QR code generation, using various tools and libraries such as Gmail, Python, email.message module, SSL library, smtplib library, and QR code library.
Full Transcript
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 going to build 20 different python projects so this is a list of all the projects that we're going to build in this video so we're going to build a lot of projects like a dice Runing simulator a quiz program an email cizer a binary search program an image resizer 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 Tomy 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 through 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 inse security so if I scroll down a little bit you'll see two Factor on tication so in this two Factor on tcation 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 but then once you do all of that that step is actually done what you need to do then is to into this app password so what you can just do is either go into your URL and type slapp password or you can just come here and click it directly so anyone you want to do is fine it'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 are not using any of this um options what we want to click on is this order 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 say created on this time but it hasn't said when we last used it cuz we haven't used that particular password but once you have that done that is good those two process 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 we say from email the message import email message so this email is pre-installed with python so when you install 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 that password for then you are going to input the password that we generated now this is not your email password this is the app password that we generated then we are going to input the receiver so the person that is receiving this email and once we done that we are going to specify the subject the body and then we are going to create an instance of this email and actually send the email so the 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 2 file and I have the password stored in there so what I'm just going to do is to actually import the password from that app2 file so I'm going to say from App to.py 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 to actually remove this py we just need to say from App 2 because it already knows it's 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 there so the email password is now the password that I created so for you just the way we wrote the password here you just need to write it there or for a better security you can just create an environment variable and store the password there instead so the next thing you want to do is to specify the email receiver so the person that is receiving this email and let's leave that blank for now we're going to come back to do that and then let's 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 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 whatever I want to say you say um when you watch a video please 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 say 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 we are sending from and then em 2 is equals to email receiver and then em subject is equals to the subject and then we also need 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 do 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 and we're going to create a context but for us to create this context we need to import something named SSL and smtb Library so we're 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 peip 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. SMTP when you saycore SSL what we're going to use is the Gmail SMTP so we're going to say smtp.gmail.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 do 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 do sendmail now this is when we're actually sending the mail what this is doing is this is logging in with those you know those this particular credentials that we gave it and then once we have been able to login we are not going to send email so from email sender this is the person that we 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 saying to our string so we want to send all of this and this should 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 this let's actually use a temporary email we come to Google and let's just say tempmail 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 generated R 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 damage our program works so let's come back in here now and in the email receiver 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 success y let's go back and see if you come here now you can see that it says from code we told me@ 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 cuz 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 you know talk about what we did first of all you have to go to your account and set up the two Factor dedication 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 email 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 uh 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 to me let me say and I I I right and what we're going to do is to have a variable that says what 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 do 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 it with word replace bement 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 ask us for the word to replace we 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 guys I am to me an a a a a so that is how to use this basic word replacement you know method and you can it to build you know whatever you want to build or whatever you think of but that is how to build a simple World 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 defy 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 input 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 y Loop to continue the program until the user wants to exit so this is the steps we're 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 equal 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 and 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 to 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 or something like that then we don't need to convert it to string or even use cation 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 equal to a minus B and then we're going to print exactly the same thing and what we are 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 answer is equals to A * B and then we're going to print exactly the same thing and say string a plus then we're going to use the aeric sign which is also the multiplication sign then concatenate with string B concate will equals to plus string answer now for the last function divide A and B just like we been doing and we're going to say answer = to a / B and then we're just going to print string of a concate plus string of B concatenate equals to then Cate 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 then we're also going to print B is subtraction we're going to print C multiplication then we going to print D Division and then we're also going to print the last one so that we will know when to break out of the y Loop exit and there now we have this what we want to do is to now have a variable named 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 cap 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 add add condition and then we're going to ask for the input so input and then we're going to say input first number but then we have to convert all of this to an integer because we are dealing with numbers and then we're going to do exactly the same thing for the second one and say input and let's just them to input second number now 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 C 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 if choice is equals to b or choice is equals to capul letter B then we're going to print so 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 El if choice is equals to C or choice is equals to Caps letterer c 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 leave 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 El if choice is equals to e or choice is equals to cator 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 and we've got the quit function so the whole thing should be working now the whole program should be working and we don't need this choice because that's not the choice we're using so the the whole program should be working with Define all the functions show the options to the user allow the user to pick what he wants collected the values and then Cod the function now let's see what this gives us so let's say I say B subtraction first number is 5 second number is 2 5 - 2 = 3 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 you 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 print let's say while true so while true is going to do this for us and we're just going to put all of this under the W 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 the user input 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 35 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 you know 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 see five and five so as you can see there's a little bit of space here before the next you know Program start 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 understood everything we did in this tutorial and that is working successfully in this tutorial we're going to be building an email slier so what an email slizer is it's that it a program that takes a particular email and then slices it into the usern name 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. or just come so let's do that before we get started let's work 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 what we want to do next is to then slice or split the email using the ad 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 cod with toy.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 splited as one and we're 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 going to be let's just save 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 tomy.com and the first part is now going to be the domain which is code with toy and the second part is going to be this. 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 toy.com so what we're now going to do is now split this second part again using this dot so then we're going to have code with to me and then we're going to have come so let's do that real quick so what we just want to do is to have a new function and we can just name this function main it's not going to take any input or I just going to we can print something and say welcome to the email slicer and once we have this let's just print A blank sentence or a blank word so we can 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 what 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 once I split it is this is going to take the first part and the second part of the split so this is going to be equals to email input do split so we're splitting it using the at so what this is going to do now is that once we split it the first part is going to be equals to this variable and the second part is going to be equal to this variable so now that we have that splitted we have the username done we can print the user name but for the domain let's now say domain and extension so what we want to do now is to say domain do split using the foot stop so what is is doing now is is updating this domain with the something like this so hello at cod with toy.com so now we add this as a domain in the initial split once we split when we splitted it using at so we had code with tomy.com as the domain but we now want to update the domain to just be code with toy and then the extension to be come so what we're going to do is domain equals do 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 let just use comma inste of using continuation so we can just say username and we're going to print domain this 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 Cod with.com so you can see it says the username is hello the domain is code with to me and this is the extension so that worked successfully we can take a little bit further and just keep you know looping it by saying while 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 as blank at gmail.com so it says blank Gmail and that is the extension and it ask us to input again so now we can say hello at code with tomy.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 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 till the target value is found so let me explain what this actually means for example what binary search does is that it takes a 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 1 2 3 4 5 6 7 8 9 right and let's add 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 add it together then divide it by two so this is zero and this is 0 1 2 3 4 5 6 7 8 9 so this is nine then it's going to do 0.0 + 9 basically something like this 0 + 9 then it's going to divide the answer 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's just discards the0 five and uses four so this is four right with an index value of four then it's going to check if three is greater than or less than that four since three is less than it it's going to discard the whole list that is after the medle value so this is going to be deleted and then it's going to focus on just this particular list then it's 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 half right since three is equals to that particular mid value or mid 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 it's going to discard all of this again from here and then it's going to look into this particular list then it's 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 the way binary search works it takes a list competed 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 if we want to brainstorm this let's write a few steps which we're going to take so disable 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 the target parameter so this is going to collect list 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 true for the data or it has split that set of data into half so imagine we have to split that data into half three times before we get the particular Target that means the amount of steps gone through is three steps so we also want to have a variable that tracks that then once we do that we can either use a recursion we can either use recursion or a y Loop to keep because as I said we're going to repeatedly split that data so we can either use a while loop but if we're using a while loop that means we are updating the datas by ourself manually and if we using a recursion we're just going to call the function inside itself 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 going to 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 we want 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 w Loop so we're just going to return something like minus one to you know keep then we're going to use the while loop that says something like while the start 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 sh function as I said is going to take list and let's say element we can say Target we can say element anything you want to say and in here what we want to do is to say middle equals to Z so these are the variables that we are defining now middle is equal to Z start is equals to Z 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 hasn't split data yet so now that we have all of this the next thing to do is to use a w Loop so we're going to say while start is less than or equals to to end so basically we want to keep doing this until this 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 whole 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 we want 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 say Steps step comma STS just leave a space and let's say something like so we're going to do comma here also yes and we're going to have list which is this list then we're going to let it start from the start and end at the end but we have to add plus one here so what this is is that we are now saying show this list but show it from the index of start which initially is zero and end which initially is the length of the string so let's convert this to a string so we don't get no errors so this is what it's going to show 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 it's 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 this start is 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 + one and middle this is one of the most crucial parts so this is when we actually splitting the data into half so start 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 are going to say if the element which is the target value basically is equals to List middle so if the middle which is what we got from here the value we get if that is equals to the element or the Target that we're looking for then let's just return mid as the data found but if let's add another condition that says if element is less than List middle so that mean if it's less than the list 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 is saying is we have a list right 1 2 3 4 5 and it's saying if the element which is let's say two let's 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 element is less than that so if element which is two that we're looking for is less than three then we 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 3 minus one and the reason why we did minus one is because all indexes start from zero so this will be 0 1 2 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 1 2 3 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 it's 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 we want to say start is equal to Middle + 1 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 mid that me is greater than the middle then want to update the start to Middle + one if I quickly use that same example 1 2 3 4 5 and the value is let's say four in this 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 it is greater then the start is now middle + one so middle is three so we're going to say middle + one the what we're going to do now is 0 1 2 right then we're going to add one to that that's why we're going to have 0 1 2 3 so from here it's going to discard the rest of this and it's just going to only have this particular list as the 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 a 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 going to run this function let's have a list let's say my list is equals to 1 2 3 4 5 6 7 8 9 and let's say our Target is equals to let's 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 cuts this list 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 and he also Cuts this list here to give us one if we're 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 n 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 here 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 as I said you can use you know a recursion which is uh 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 W 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 are using a let's say normal like a linear search or that which is the normal way of searching stuff and the linear search is where it 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 uh linear search is because of the time complexity binary search is far more quicker than a linear search because binary search doesn't have to look through every single value in the data or in the list but for a linear search it has to look through every single data till 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 it doesn't look through that because you know this the data we're looking for is no more there then it focuses on where it thinks it's going to be split all of this again and you know keep doing that which saves more time but imagine we are actually using a linear search so let's see how a linear search is going to work and we're looking for 12 what we're going to do is something like four 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 1 2 3 4 5 all the way till it 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 stretch 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 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 the 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 go 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 once we have that dictionary Loop through that dictionary before we Loop through the dictionary let's actually have a variable that track discore of the player then we want to um Loop through the dictionary using the key P key value PA 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 cre is 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 PA the key values PA then display each question to the user and allow them to answer then tell them if they are right or wrong and then show the final result let's actually leave this here and follow this steps so the first thing we're going to do is to have the squeeze 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 what is the capital of Germany and then 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 what is the capital of Italy and let's have our answer as R so just to save time we're going to copy and paste this so let's copy and paste this four more times one two now so right here 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 list or dictionary of the questions and in each of those question we have the question and the answer so what we can do now is to Loop through all of this show it to the user and then you know continue from there so before we do that let's see it says we should have a varable that tracks the score so this is very easy just say score equals to Z 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 specially not the normal Loop because it's a dictionary we 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 four key value in quiz do items so this is way 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 we're 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 do lower is equals to Value answer the lower then the user is correct so let me tell you I using lower so basically because python is case sensitive if we don't use lower what is going to do is that imagine the user types burn but doesn't put the capsul letter on B let's say the user types this it's going to mark it as wrong but what I'm doing is I'm converting whatever the user write into lower case and I'm converting the main answer also into lower case 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 the user 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 corrent answer so we say print the answer is then we're going to say value but now we want to say answer and let's also print their 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 cap 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 two imagine I okay since we already have that we can't test it what I wanted to do is to test let's say we have all caps imagine 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 it's 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 to packed so what we can just do is to have a little bit of spacing so right here where we have score we can just say print blank let's also PR blank there here and also write here print blank and we do the same thing again so we have that done what we actually want to do is that after all of this we want to tell the user final score and we also want to tell them the percentage so let's say print I'll say something like you got string SC four 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 and we can say your percentage is cona let's first make sure we're converting whatever we're doing into string so we're going to say score ided by 7 * 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 sck that and reload it so let's just get like two out of it so par is you can see that now there spacing so we can see well so we've got into let's start getting of it 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 just do is to actually convert this to an integer so that you know it doesn't show like all of this decimal points with it so right here we can just say int and you actually want to convert an integer before converting to a string you don't want to convert it to a string before converting to 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 it take a lot of time and I hope you understood what we did to this point in this tutorial I'm 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 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 collect the text and convert 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 first open up a new terminal and let's install the packages needed so so I'm on a Mac so I'm going to use pip 3 to install if you're on the Windows you don't need to use pip 3 just type pip 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 it should 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 whatever 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 underscore correction is equals to QR code do constants do error underscore correct underscore L and box size is equals to 10 and let's say B 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 whatever 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 going to say qr. add data so this is just going to add the data first I'm going to say text and QR the 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 want to fill it with a color of black you can input what
Original Description
Improve your Python skills by learning how to code 20 beginner Python projects.
💻 Code: https://github.com/tomitokko/20-python-projects
✏️ Course developed by CodeWithTomi. Check out his channel: https://www.youtube.com/c/CodeWithTomi
🔗 Join CodeWithTomi's Discord Server: https://discord.gg/cjqNBHHhKV
🔗 Twitter: https://twitter.com/TomiTokko3
❤️ Try interactive Python courses we love, right in your browser: https://scrimba.com/freeCodeCamp-Python (Made possible by a grant from our friends at Scrimba)
⭐️ Course Contents ⭐️
(0:00:00) Introduction
(0:00:41) Email Sender
(0:12:15) Word Replacement Program
(0:14:35) Basic Calculator
(0:28:21) Email Slicer
(0:35:20) Binary Search Algorithm
(0:53:48) Quiz Program
(1:07:04) QR Code Generator
(1:13:58) Interest Payment Calculator
(1:21:51) Random Password Generator
(1:31:41) Dice Rolling Simulator
(1:38:47) Site Connectivity Checker
(1:47:29) Currency Converter
(1:51:53) Leap Year Checker
(1:55:53) Word Dictionary
(2:07:41) Rock, Paper, Scissors
(2:19:39) Python Face Detection
(2:27:14) Python Automation
(2:39:02) Web Scraper
(2:47:28) Image Resizer
(2:57:34) Graph Plotter
🎉 Thanks to our Champion and Sponsor supporters:
👾 Raymond Odero
👾 Agustín Kussrow
👾 aldo ferretti
👾 Otis Morgan
👾 DeezMaster
--
Learn to code for free and get a developer job: https://www.freecodecamp.org
Read hundreds of articles on programming: https://freecodecamp.org/news
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from freeCodeCamp.org · freeCodeCamp.org · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
React: Production Server Setup Part 2 - Live Coding with Jesse
freeCodeCamp.org
cookies vs localStorage vs sessionStorage - Beau teaches JavaScript
freeCodeCamp.org
Browser history tutorial - Beau teaches JavaScript
freeCodeCamp.org
Graph Data Structure Intro (inc. adjacency list, adjacency matrix, incidence matrix)
freeCodeCamp.org
React: Parameterized Routing with Next.js - Live Coding with Jesse
freeCodeCamp.org
React: Dealing with jQuery Issues - Live Coding with Jesse
freeCodeCamp.org
setInterval and setTimeout: timing events - Beau teaches JavaScript
freeCodeCamp.org
Browser and Device Testing - Live Coding with Jesse
freeCodeCamp.org
Last Minute Updates - Live Coding with Jesse
freeCodeCamp.org
Post Launch Updates - Live Coding with Jesse
freeCodeCamp.org
React: Setting Up Google Analytics - Live Coding with Jesse
freeCodeCamp.org
React: Masonry Layout - Live Coding with Jesse
freeCodeCamp.org
Load Balancing Digital Ocean Droplets - Live Coding with Jesse
freeCodeCamp.org
try, catch, finally, throw - error handling in JavaScript
freeCodeCamp.org
Load Balancing: SSL Passthrough Setup - Live Coding with Jesse
freeCodeCamp.org
Graphs: breadth-first search - Beau teaches JavaScript
freeCodeCamp.org
React: Masonry Layout Part 2 - Live Coding with Jesse
freeCodeCamp.org
React: WordPress API Live Search - Live Coding with Jesse
freeCodeCamp.org
Creating WordPress Custom Post Types - Live Coding With Jesse
freeCodeCamp.org
Dates - Beau teaches JavaScript
freeCodeCamp.org
Miscellaneous Front End Updates - Live Coding with Jesse
freeCodeCamp.org
Merging a Pull Request from GitHub - Live Coding with Jesse
freeCodeCamp.org
React + Prettier + Standard JS - Live Coding with Jesse
freeCodeCamp.org
React: Sortable Responsive Table - Live Coding with Jesse
freeCodeCamp.org
Geolocation Sorting by Distance - Live Coding with Jesse
freeCodeCamp.org
Tradeoff Matrix - Agile Software Development
freeCodeCamp.org
The Definition of Ready - Agile Software Development
freeCodeCamp.org
Getting first React job without experience - Ask Preethi
freeCodeCamp.org
React: Google Analytics Click Tracking - Live Coding with Jesse
freeCodeCamp.org
Submitting a PR to an Open Source Project - Live Coding with Jesse
freeCodeCamp.org
Should I go back to school to get CS degree? - Ask Preethi
freeCodeCamp.org
Hero Section CSS Changes - Live Coding with Jesse
freeCodeCamp.org
Working Agreement - Agile Software Development
freeCodeCamp.org
A day at Pennybox with Co-Founder Reji Eapen
freeCodeCamp.org
React: Sorting and Filtering Data - Live Coding with Jesse
freeCodeCamp.org
React: Sorting and Filtering Data Part 2 - Live Coding with Jesse
freeCodeCamp.org
React: Building a New UI - Live Coding with Jesse
freeCodeCamp.org
Definition of Done - Agile Software Development
freeCodeCamp.org
Getting started with jQuery (tutorial) - Beau teaches JavaScript
freeCodeCamp.org
Making a React Blog with WordPress Content - Live Coding with Jesse
freeCodeCamp.org
React, NextJS, CSS - Live Coding with Jesse
freeCodeCamp.org
jQuery events - Beau teaches JavaScript
freeCodeCamp.org
React/NextJS Routing and WordPress API Custom Types - Live Coding with Jesse
freeCodeCamp.org
React: Working with API Data - Live Coding with Jesse
freeCodeCamp.org
React: Refactoring Components - Live Streaming with Jesse
freeCodeCamp.org
jQuery effects - Beau teaches JavaScript
freeCodeCamp.org
More React Refactoring - Live Coding with Jesse
freeCodeCamp.org
animate in jQuery - Beau teaches JavaScript
freeCodeCamp.org
"Finishing" My React Site - Live Coding with Jesse
freeCodeCamp.org
Starting a New React Project (P2D1) - Live Coding with Jesse
freeCodeCamp.org
React Project 2 Day 2: Learning Material UI - Live Coding with Jesse
freeCodeCamp.org
The Agile Manifesto - Agile Software Development
freeCodeCamp.org
jQuery: get and set with http, text, val, and attr - Beau teaches JavaScript
freeCodeCamp.org
React Project 2 Day 3 - Live Coding with Jesse
freeCodeCamp.org
The INVEST approach to product backlog items
freeCodeCamp.org
React Project 2 Day 4 - Live Coding with Jesse
freeCodeCamp.org
Chickens and Pigs - Agile Software Development
freeCodeCamp.org
React Project 2 Day 5 - Live Coding with Jesse
freeCodeCamp.org
jQuery: add and remove DOM elements - Beau teaches JavaScript
freeCodeCamp.org
React Project 2 Day 6 - Live Coding with Jesse
freeCodeCamp.org
More on: Research Methods
View skill →Related Reads
📰
📰
📰
📰
The Minecraft anvil is a tree-cost optimization problem in disguise
Dev.to · Mark
KMP Algorithm (Knuth-Morris-Pratt): The Smart Way to Perform String Matching in O(N)
Dev.to · Jaspreet singh
Every Backtracking Problem Is the Same Three Lines. I Just Couldn't See the Tree.
Dev.to · Alex Mateo
DSA From Zero to Hero #3: Sliding Window (Fixed Size) Explained With a Java Example
Medium · Programming
🎓
Tutor Explanation
DeepCamp AI