hey there I'm mosh and welcome to python projects for beginners in this course we're not just going to build some cool python projects we're going to dive deep into the process of thinking like a programmer coding isn't just about getting things to work it's about understanding the problem breaking it down and Building Solutions that are clean maintainable and actually make sense most courses will show you how to write code but they don't teach you why you're writing it that way here I will walk you through my entire problem solving process from the initial idea to
the final polished Solution by the end of this course you won't have just cool projects under your belt you'll have the skills to tackle coding challenges with confidence and write code that you can be proud of so if you're ready to go beyond just coding and start thinking like a problem solver let's dive into python projects for beginners [Music] now before we jump into projects I want to quickly talk about what you'll need to know to get the most out of this course you don't need to be a python expert to follow along just a
basic familiarity with python is all that's required if you know how to work with variables Loops functions and maybe a little bit of file handling you're all set as we go through the projects I'll be using some more advanced python features here and there but don't worry I'll explain those Concepts thoroughly as we encounter them if you feel like you need a little refresher or you want to Di deeper into python I've got you covered you can check out my Python tutorial on YouTube where I'll walk you through the basics in a clear and easier
to understand way and if you're looking to really Master python I've got a full course on my website that takes you from the basics to advanced concepts the links are below this video now I want to quickly go over some of the materials that come with this course first we have the project handbook this is a PDF that outlines all the projects we're going to work on together for each project I've included additional challenges for those of you who want to push yourselves further next all the code we write in this course is available on
GitHub this is where you can find the complete source code for each project whether you want to compare Your solution with mine or just grab the code to experiment with it's all there for you you'll find the links to both the project handbook and the GitHub repository right below this video all right with that out of the way let's move on to the next [Music] lesson before we dive into the projects I want to take a moment to talk about how I've structured this course and how you can get the most out of it I've
designed this course to be Hands-On and practical for each project I'll start by showing you the project and its requirements at this point I encourage you to pause and try to work on this Solution on your own this is where the real learning happens by thinking through the problem and applying what you have learned so far once you have given it a shot come back and watch How I break down the problem into manageable steps and start coding the solution your code may be different and that's totally fine I don't expect your solution to be
exactly like mine we all think differently use my solution and code AS inspiration to see if there are better ways to write code for the first few projects if you feel like you're not quite ready to start and finish a project on your own just watch my solution and C along with me then once you have a bit more confidence tackle the other projects on your own and then come back to see my solution for ideas to improve your code look I've been coding for over 25 years and I still encounter challenges depending on the
projects I'm working on so if you find some of these projects difficult don't be discouraged that's part of your Learning Journey the things that feel complex today will eventually become simple and you'll be ready to take on new challenges remember this course isn't about quick wins it's about building a strong foundation in problem solving that will serve you throughout your career by the end of each project you will not only have a working solution but also a deep understanding of the logic and thought process behind it now let's get [Music] started all right for our
first project we're going to build a dice rolling game so let me show you what happens when we execute this program first we get this question roll the dice here we have only two options yes or no if we type anything else we get an error message saying invalid choice now we can type of Y either lowercase or uppercase it doesn't matter and every time we get two new random numbers just like how we roll a dice now if you type n our program terminates and displays a message saying thanks for playing now I want
you to spend 10 to 20 minutes on this project and then come back and see my solution [Music] all right before we jump into coding I always take a moment to map out what I want to do kind of like checking a map before we start a road trip it helps me see the big picture and avoid getting lost along the way so let's quickly plan our approach before we start writing any code trust me it makes things much smoother so in this python file I'm going to use comments to map out how this program
should behave so first we should ask the user a question like roll the dice then we should check the user input so if user enters y then we should generate two random numbers and print them otherwise if the user enters no then we should print a thank you message and terminate the program otherwise if the user types anything else we want to print an error message like invalid choice now we want to make sure that the user can keep playing until they decide to terminate the game so we should put these instructions inside a loop
for repetition so everything here should go inside a loop an infinite Loop okay now let's start converting these comments into actual code so first we're going to ask the user to roll the dice and to do that we use the input function now here we should type a prompt we can use double quotes or sing quotes different people have different preferences whatever you like just make sure to stick to that so here I'm going to ask roll the dice and give the options yes or no we add a colon followed by a whit space so
whatever the user types will be separated from our prompt okay now we store the result in a variable we can call it Choice next we should check if Choice equals y so if Choice equals a lowercase y or Choice equals an uppercase y that's one way to do this but there is a smarter way we can treat whatever the user types as lowercase so look if you hover our Mouse over this Choice variable look at the type the type is a string so the input function returns a string and you know that in Python string
objects have a bunch of methods so here we can use the lower method to convert whatever the user types into lowercase with that we can get rid of the second condition okay now we should generate two random numbers and to do that first we have to import the random module now in this module we have a method we can call random. Rand int to generate a random integer or a random number between these two numbers A and B in this case one and six now this returns a random number so we store it in a
variable like die one now we have to repeat this to generate the second random number next we should print these numbers so here we call print now for Simplicity we can use a formatted or an F string so we type an F before our quotes and here we add parenthesis inside the parenthesis we want to print our random numbers like one and two but instead of hardcoding these numbers we want to print the actual random numbers that are generated here so we replace one with curly braces to add a placeholder or a hole in our
string and inside this hole we add d one and similarly replace two with curly braces and add die two so we print these numbers next we should check if the user types an N so L if Choice equals n then we want to print a thank you message so thanks for playing now to terminate the program we want to break out of our Loop now we haven't added the loop here so on the top now there are two ways to do this some people like to declare a variable like running or playing and initialize it
to true then they add it as the loop condition so while playing is true then we're going to repeat these instructions and and when the user types an N we can use the break statement to jump out of this Loop that's one way but there is a better way this variable here is really unnecessary so we can use true as the condition for this Loop and get rid of one extra line of code also note that it's a good practice to add a line bre between our import statements and the rest of the code it
makes our code cleaner and easier to the eyes so we're almost there now finally if the user types anything else we want to print an error message so print invalid Choice as simple as that that was our first project depending on your programming skills this might be too easy for you but don't worry as we go through this course our projects will gradually get more complex now if you want to challenge yourself look at the workbook that I give you at the beginning of the course after each project there are ideas for enhancing the program
and challenging yourself all right for our next project we're going to build a number guessing game so here is how it's going to work when we run our program it generates a random number between 1 and 100 that we have to guess now if we type an invalid number like a we get an error message so let's type a valid number like 50 now the program is giving us feedback it says this is too high so let's try 25 it's still too high what if we try 10 still too high how about five now it's
too low so the number that the computer has generated is between 5 and 10 let's try seven it's too low let's try eight there you go we guessed the number so spend 15 to 20 minutes on this project and then come back and see my solution all right once again before we write any code let's map out what exactly we're going to do so first we should have our program generate a random number then we should ask the user to make a guess now we want to make sure that the user enters a valid number
so if the user enters an invalid number so if not a valid number then we want to print an aror otherwise we should give the user some feedback so we can say if this number that the user entered is less than the number to guess we can say this is too low otherwise if this number that the user entered is higher than the number to guess we can say this is too high otherwise that means number equals guess right so in this situation we should say hey well done you made a guess now we want
to make sure that the user can make multiple guesses so except the first line we should put the rest of our code inside a y Loop for repetition so here's the structure of our program we don't want to add the first line inside the loop because we want to generate a random number only once okay now let's convert these commments into actual code to generate a random number first we import the random module then we add a line bre to separate our import statement from the rest of our program next we call random. randint to
generate a number between 1 and 100 let's store this in a variable called number to guess always use descriptive names for your variables so don't use variable names like n or X or a because someone else reading your code they have no clue what these variables represent okay so number two guess next we should ask the user to make a guess so I don't want to add the loop yet let's just convert this comment into code so here we call the input function and tell the user to guess the number between one and 100 now
you know that the input function returns a string so we can store it in a variable like user input now we should convert this to a number and to do that we use the int function we pass user input and store the result in a variable called yes now look user input is only used in a single place there is no need for this variable anywhere else in this program because for the rest of our program we're going to work with this integer so we can simplify our code and make it more concise by removing
this variable it's unnecessary so we can get the string that is returned from the input function and pass it directly to the int function with this we can remove this unnecessary variable so when this program is executing first the input function is called then the return value which is a string is passed to the int function okay now how can we validate that this is a valid number well before we do that let's just print yes on the terminal to see if our program works up to this point so this is a good technique for
building larger programs always do it in baby steps so instead of implementing the entire program do it in baby steps make sure it works and then move on so so here in the terminal let's run our program and enter an invalid number like a all right look our program crashed because an exception is thrown on this line and here's the type of the exception value error so to handle this situation and prevent our program from crashing we have to add this line inside a tri block so we type try then add indentation now right after
try we should type accept followed by the type of error we want to handle in this case value error okay now if we end up here we want to print an error message and say please enter a valid number okay let's run our program one more time so I type A okay this time our program didn't crash instead we got a friendly error message beautiful so we're done with this step now we should give the user some feedback so after the accept block I want to add a line bre to separate this bit of logic
from the rest of the logic which is about giving the user some feedback so using these line breaks is like how we break up a story into multiple paragraphs imagine if you read a book and there are no paragraphs obviously reading that book is very difficult so here we can check if gu is less than number to yes reprint a message and say too low now here we have an error message on the guest variable saying guess is possibly Unbound I know this is a weird error message but basically this is happening because we have
declared this variable inside the tri block so it's only meaningful inside the tri block this is called the scope of this variable so to fix this error we have to move these two lines inside our Tri block and add anotation so we read a number then we check if it's less than the number to guess otherwise L if guess is greater than number to guess we print to high otherwise that means the user guessed it correctly so here we can say congratulations you guessed the number now let's get rid of these comments we don't need
them anymore now we want to put all these instructions inside an infinite Loop so here we type while true and move all these lines inside our Loop now after congratulating the user we should use a break statement to break out of this Loop okay now let's run our program and see what happens so first we enter an invalid number okay we got an error message so we can try again let's type B this time beautiful now let's type a number like 50 it's too high let's try 25 it's too low so let's try 40 too
low what about 45 too high so it's between 40 and 45 let's try 43 it's too low it has to be 44 okay our program [Music] terminated all right our next project is a fun game that we have all played in our childhood rock paper scissors game now this project is a little bit more challenging than the previous projects so let me run the program and show you how it works first we get a question rock paper or scissors here we only have three choices r p or S if we type anything else we get
an error message saying invalid choice now let me go with r that is short for rock so I chose Rock computer chose paper and I lost now right after we get asked if you want to continue let's try again this time I'm going to go with scissors so I chose scissors computer chose paper I want now I don't want to continue so let's type in the game ends again this project is a bit more challenging than the previous ones so spend about 20 to 30 minutes on this and then come back and see my [Music]
solution all right once again before we write any code let's map out what we're going to do so first we're going to ask the user to make a choice now if the choice is not valid we're going to print an error otherwise we should let the computer to make a choice as well next we should print the choices using emojis and this is the font part next we should determine the winner and finally we ask the user if they want to continue if not we're going to terminate the game so this is the structure of
our program now let's start coding so first we should ask the user to make a choice to do that we use the input function here we type rock paper or scissors and in parenthesis we can type the valid options so R P and S now we get the result and store it in a variable called user Choice next we should validate the choice so just like before here we're going to call the lower method so we can treat the user's input as lowercase text we talked about this technique in one of our earlier projects now
to validate the user's Choice here we can use a bunch of if statements so we can say if user Choice does not equal R and user Choice does not equal p and user Choice does not equal s then we can print an error message and say invalid Choice that's that's one way but this is not a very clever or very professional way to implement this there is a better way we can store the list of valid choices in a list and then check to see if the user's choice is in that list or not so
in the first line we can declare a variable called choices and initialize it to a list of valid choices so R P and S now we can simplify this if statement and say if user choice not in choices then print an error message this implementation is more concise and more elegant now we can further improve this and convert this list to a topple why because lists can be modified in our program so somewhere you might accidentally modify the list and use the append method to add a new item to the list or remove method to
remove one of the existing items this could be an accidental mistake but if you convert this to a top hole it becomes read only so top holes look they don't have the remove or append methods so a topple is just like a readon list okay so we have our valid choices and we are done with this step now before going further Let's test our program so I'm going to remove these two lines now back to the terminal let's run our program so if you type a we get an error message beautiful but if ify Type
R we don't get an error great next we should let the computer to make a choice and to do that first we have to import the random module now earlier we used the Rand in method to generate a random number between two numbers but here we want to use a different method and that is Choice with this we can pass a list or a top hole like choices and let the computer choose one of these valid choices so so let's store the result in a separate variable like computer choice so we're done with this step
now let's print the choices so first I want to print the choices without emojis just to make sure that our program is working up to this point so here we can type you chose and then use concatenation to append user's Choice here that's one way but a better and more elegant way is to use a formatted string so we prefix the string with an F which is short for formatted and here we add curly braces to insert a value dynamically in this case user Choice with this we don't have to use concatenation okay similarly we
can duplicate this line and say computer chose and here we add computer Choice okay let's run our program so I Type R okay we both chose Rock let's try again that's weird it's happening twice let's run it one more time I'm going to select s okay so I selected scissors computer selected Rock beautiful now we should print emojis how can we do that well there are two ways one way is to use an if statement and say if user Choice equals R then we can print an emoji on Mac you can bring up the emoji
keyboard by pressing control command land and space on Windows I'm not entirely sure so here we can type Rock and select this rock okay now similarly we can add a second condition and say if user Choice equals s then we're going to print scissors but again this approach is not the best way because we need three statements to map these letters to emojis let me show you a better way first let me remove these few lines okay now in Python we have a data structure called a dictionary a dictionary is used to map a key
to a value so we can map the character R to the emoji of a rock similarly we can map the letter s to scissors okay now how can we declare a dictionary well here we can declare a variable called emojis and set it to curly braces inside the braces we type key value pairs so our key is going to be R then we type a colon and map it to the emoji of a rock note that in this case both our key and value are strings but this is not a requirement so we can map
a string to a number or an object whatever we want to do now similarly let's map s to scissors and also P2 paper okay now let's remove these comments back to the part about printing the user's Choice instead of printing the user's Choice which is a letter like r p or S we are going to go to this dictionary and look up the value associated with a given key so here we type emojis then using square brackets we can look up the value associated with one of these Keys now here in the aut completion box
we can see the valid Keys which are p r or S but we're going to replace this with user choice now similarly here we type emojis and pass computer Choice let's run the program one more time if I type R I get rock and computer chose Caesar beautiful all right we're done with this step the next step is deter determining the winner now before moving forward I want to add some line brecks to divide our code into different segments just like the paragraphs of an article so on the top we are declaring our emojis and
valid choices these two lines are highly related so I want to keep them together but look at the next line the next line is about getting the user input this line has nothing to do with the previous lines so it's like a different paragraph in a story so here we add a line break now again these three lines are highly related because they are part of getting the user's input so we want to keep them together but separate them from getting the computer's choice now once again we add the line break here because this segment
is all about printing the users and computer's Choice okay now let's move on to the next segment which is determining the winner so we add a line bre and here we can check if user choice is the same as computer choice then we print Tai elif or Al if now here we want to implement the scenario where the user wins there are three scenarios one is user choice is rock and computer choice is scissors in this case we want to print uin there's another scenario where user choice is scissors and computer choice is paper again
here we can print you win but there is a better way we can combine these two statements into a single statement using the logical or operator so this is one scenario or one condition where the user wins as you can see I've selected this expression now we type left bracket so the entire expression is now surrounded by parenthesis right after we type or now here we should select our second condition again we type a left bracket to surround this with parentheses now we select the entire expression cut it and put it right here now similarly
we type another or operator and add the third condition and that is user Choice equals P or paper and computer Choice equals Rock so if any of these conditions is true the user wins otherwise the user loses okay now this line is getting a little bit too long so to make our code more readable we can break it down into multiple lines so right after this or operator we add a line bre now here we have an error saying expected expression because python interpreter expects a colon here so to tell The Interpreter that this is
a multi-line statement here we add a backslash okay now to better format our code it's better to line up all these conditions so we put this on a new line add tab again on this line we add a backslash now these two conditions are perfectly align now similarly let's add another backslash and put this condition on a new line now what is happening here we had an extra white space okay we're good so this is one way to break this code down into multiple lines but all these backs slashes are kind of ugly let me
show you a better way look here we have three conditions each surrounded by parenthesis now we can grab all these three conditions and wrap them with parenthesis like this we can remove the backslash here we add parenthesis so the left one is here and the right one should be at the end right here with this we no longer need these back slashes anymore so python interpreter knows that the this outer parenthesis represents a long expression okay so we're almost there we determine the winner next we should ask the user if they want to continue so
once again we add a line break to separate this segment from the previous segment which is about determining the winner and then use the input function to ask the user if they want to continue or not so right away we call the lower method and then store the result in a variable like should continue we cannot use the word continue because this is a reserved keyword in Python okay so here we check if should continue equals n then we want to terminate the program now to do this first we have to add these statements inside
a y Loop so here we add a y loop with true as the condition now let's indent all these lines so if the user types an N then we want to break out of this Loop to terminate the program otherwise if they type why or anything else we can treat it as yes so let's run our program first let's try an invalid Choice like a all right our program crashed on this line line 13 where we try to show the Emoji associated with the user's choice now obviously in this dictionary dictionary of emojis up here
we don't have a key with the value of a right so look down here we validating the user's choice if the user types an invalid choice we just print an error message but the rest of the code gets executed so we end up on this line and this line throws an exception to fix this issue right after printing an error we should use the Contin Contin statement to jump back to the beginning of the Y Loop so we ask the user one more time to make a choice let's try it one more time if I
type an a we get an error message and our program doesn't crash beautiful let's try again B great now if I type R I chose Rock computer chose scissors and I want beautiful now shall we continue if I type yes I get a chance to make another Choice let's go with P I chose paper computer chose Rock so I want again great now if I type in our program terminates all right our program is working but just because it's working it doesn't mean our work is finished we should always review our code and find Opportunities
to refine and improve it in coding this is called refactoring it's basically a fancy term for changing the structure of our code without changing its functional ity in this lesson we're going to look at a common refactoring technique called modularization modularizing code means breaking down a large program into smaller reusable Parts called modules or functions think of it like organizing a messy room into different boxes each holding specific items instead of having one big pile of everything we put related things together making it easier to find what we need and keep things tidy now back
to this code earlier we talked about different segments in our program so we have a segment for displaying choices we have another segment for determining winner and so on now we're going to extract these segments into small functions each having a single responsibility let me show you how we do this so we start from the top these few lines have a single responsibility and that is getting the user's choice so we can extract these few lines into a separate function called get user choice so up here after we declare our emojis and choices let's define
a function called get user choice always use descriptive names for your functions okay now let's move these few lines inside this function now here we have an error because the continue keyword can only be used inside the loop so here we need to add a y Loop while true then we move these view lines inside this Loop so if the user enters an invalid choice we print an error and then continue which means we jump to the beginning of the Y Loop otherwise we break out of this Loop and at the end we should return
a value from this function what value user's choice so here we use the return statement to return user choice now there is a better way to write this code instead of breaking out of this Loop we can return user's choice right here so return user Choice with this we can make our function slightly shorter okay now let me show you what happens if we swap these if and else statements so instead of checking if user choice is not in the list of choices we check if user choice is in the list of choices in this
case we're going to return immediately so return user Choice otherwise we are going to print an error message and continue okay now with this implementation we don't even need the continue keyword because if we end up here we print an error and then the control automatically moves to the beginning of the Y Loop so we can get rid of the continue statement and make our code slightly shorter okay now back to our main y Loop earlier we had a few lines for getting users input those lines are now inside the get user Choice function so
here we call get user Choice get the result and store it in a variable called user Choice okay next we're going to apply the same technique to these two lines these two lines are highly related and have a single responsibility displaying choices so let's select these two lines cut now after this function we Define another function called display choices good now back to our y Loop right here we call display choices okay next we need to extract this F lines for determining the winner again select cut let's define a new function determine winner now here
we have an error because we need to add indentation here good now back to our y loop after we display the choices we call determine winner good now we can do the same thing with our y Loop so we can extract this entire logic and put it into a separate function let's call that play game this is where we have our game logic let's select all this code and add ination good so here's the end result now if you look up here we have a bunch of Errors because in this function display choices we do
not have a variable called user choice this variable is declared inside our play game function so to fix this issue we have to pass user choice and computer choice to these functions so we go to our display choices function and give it two parameters user choice and computer choice now the errors are gone similarly in determine winner we add two parameters user choice and computer Choice the errors are gone beautiful now when calling these functions we should pass these values as arguments user choice and computer Choice one more time user choice and computer Choice good
now one last thing if we run our program nothing happens because after this refactoring we move different lines of our code inside different functions but currently none of these functions is getting called so at the end we have to call the play game function so our program starts let's run it one more time there you go let's enter an invalid Choice it's still working let's type R our program is working and let's terminate it beautiful so with this refactoring we broke down our program into small reusable functions each of these functions has only a few
lines so if there is a bug in one of these functions we can only focus on those few lines this is easier than reading and understanding an entire script this is the benefit of modularizing [Music] code we have one more opportunity for improving this code look there are multiple places where we have defined our choices this is bad for two reasons one reason is that if we have a typo in our code our program is not going to work that's number one problem the second problem is that if tomorrow we decide to change our choices
from R S and P to something else like 1 2 and three there are multiple places that we have to modify in programming we have this principle called dry which is short for don't repeat yourself so we don't want to have repetition or duplication in our code most of the time it's a bad practice practice so how can we solve this problem well we can generate this top hole based on this dictionary in this dictionary we have three key value pairs our keys are R S and P so let me show you how we can
convert this dictionary to a tople with these values first I'm going to select this line and the rest of the code now we can convert all these lines to a comment by pressing command and slash on Mac or control and slash on Windows now all these lines are commented out so they're not going to get executed we only have the Declaration of our dictionary now let's print emojis dot look here we have a method called keys which Returns the keys of this dictionary using this structure dict keys let me show you so back to the
terminal let's run our program all right here's what we get we get an object of type dict keys or dictionary keys and here we have R S and P but this is not exactly what we want what we want is a topple but this is very easy to fix we can pass the object that is returned from this method to the topple function and with this we get a top hole exactly like the top hole that we declared here so we can set choices to top hole of emojis do Keys okay with this technique we
remov duplication in our code now let's bring back all the code here so one more time we press command and slash on Mac or control and slash on Windows okay now look there are other places where we have repeated our choices again if we have a typo our program is not going to work so realistically we need a single place for defining our choices to do that we can go to the top and declare a bunch of constants by convention we use uppercase letters to declare constants so we can declare a constant like rock and
set it to R similarly scissors and paper this is a single place where we declare our choices now anywhere we have R S and P we replace them with our constants so I have selected R here now to select the next occurrence of R in this code we press command and D on Mac or control and D on Windows look this instance is also selected one more time we press command and D there you go now we have three cursors all of them selecting R so we can replace them all with rock in one go
now to cancel multic cursor editing we press the escape button twice okay one more time we're going to select s we press command and D twice to select these two instances as well and replace this with scissors again we press the skape button twice done and the last one paper okay now we have a single place where we have defined our choices so no chance for typos and if we decide to change the choices from RS and P to something else in the future there is a single place we have to update we can change
this to one two and three and everything will work okay but there is another benefit here look down here where we determine the winner our code is more descriptive so instead of comparing user choice and computer Choice with r and s we can clearly see that if the user has a rock and the computer has scissors the user is the winner hey there I hope you've been enjoying this video so far if you're finding this helpful and want to take your python skills even further I've got something really exciting for you this video is just
a taste of what you will find in my full course python projects for beginners in the full course we dive deep into more projects covering a wide range of Concepts that will help you sharpen your problem solving skills and become a confident python programmer if you're ready to level up check out the link below to get access to the full course I would love to see you there and help you on your python Journey all right for our next project we're going to build a QR code generator so first we enter some text or URL
I'm going to enter the address of my website code with mos.com next we enter a file name let's enter m.jpg now we have a QR code saved in this file this file is right here so this is the QR code for my we it if you scan this with your phone it will open your browser and take you to my website now to build this we're going to use a thirdparty library called QR code so head over to p.org proqr code read the documentation for this Library the purpose of this project is to get you
familiar with using thirdparty libraries so this project doesn't have really complex logic it's all about the right way to use third party packages so I spend a few minutes to go through the documentation then install this library and build this project all right the first thing we're going to do is set up a virtual environment a virtual environment in Python is like a separate isolated workspace on your computer where you can install packages and run python projects think of it as a clean organized room that's separate from the rest of your house in this room
you have everything you need to work on a specific Project without affecting anything else in the house now why do we need a virtual environment well imagine you're working on two different python projects one project needs an older version of a library and the other project needs a newer version if you install both versions globally for the whole computer they might conflict with each other a virtual environment solves this problem by allowing each project to have its own separate environment with its own specific versions of libraries okay so to set up a virtual environment here
we open the terminal window and type python if you're on Windows or Python 3 if you're on Mac then we type-m that is short for module we're going to run this module VM that's one of the built-in modules in Python for creating virtual environments and then we specify a name for our virtual environment by convention we often use VMV as well okay now vs code is saying we noticed a new virtual environment has been created do you want to selected for the workspace folder for now select no we come back to this later now take
a look at the project directory we have this new folder here VM and inside this we have a bunch of folders like bin include and lip inside the bin folder we have executables like pip pip 3 python python 3 and so on now if you're a bit more experienced and are familiar with Git You can see that we have over a th000 files ready to be committed to our Repository we don't want to include these files in our repository so to exclude them here in the root of our project we add a new file called
dogit ignore in this file we add the files and folders We want to exclude from our git repository in this case VN folder so we add a forward slash here okay now if you're not familiar with Git don't worry about it just ignore this step for now okay so we have created a virtual environment but current L it's not active so we go back to the terminal to activate it if you're on Windows you type VM back slash scripts back slash activate if you're on Mac you type Source VN slash bin SL activate Okay now
look this virtual environment is activated so any packages that we install will be installed in this virtual environment or in this isolated workspace when we are done with this project we can deactivate this virtual environment by typing deactivate okay now let's activate it one more time good now in this virtual environment we're going to install the QR code package all right good with this installed now we add a new file to our project QR code generator. Pi first we import the QR code module next we use the input function and tell the user to enter
some text or URL we get the result and store it in a variable called Data next we use the input function to get a file name so enter the file name and rest store it here now it's a good practice to remove any white spaces around what the user types for example what if the user types let's say the address of my website as the URL whether they type this address or this address followed by a whites space we want to have the same QR code generator so over here we can call the strip method
to get rid of any white spaces around our data okay similarly I would like to strip any white spaces around the file name good now we ready to generate our QR code to do that we go in the QR code module and create create a QR code object here we want to set two parameters one is box size I'm going to set it to 10 these are just arbitrary values I'm going to set border to four this returns a QR code object we store it in this variable next we call qr. add data then we
pass our data next we call qr. make image and set two arguments here one is fill color which I'm going to set to Black again these are arbitrary values you can use any colors you want we also set back color to white this returns an image that we store in a variable and finally we call image. saave to save it in this file and at the end we print QR code saved as now here we want to add the file name so let's convert this to a formatted string and insert the file name here now
let's run our program so I'm going to enter the address of my website code with m.com and for the file name I'm going to enter m.jpg okay now look in this folder we have mh. jpg this is my QR code so if you point your phone at this and scan it this will open your browser and take you to my website hey there I hope you've been enjoying this video so far if if you're finding this helpful and want to take your python skills even further I've got something really exciting for you this video is
just a taste of what you will find in my full course python projects for beginners in the full course we dive deep into more projects covering a wide range of Concepts that will help you sharpen your problem solving skills and become a confident python programmer if you're ready to level up check out the link below to get access to the full course I would love to see you there and help you on your python Journey