5 Mini Python Projects - For Beginners

Tech With Tim · Beginner ·📄 Research Papers Explained ·5y ago

Key Takeaways

The video demonstrates 5 mini Python projects for beginners, covering topics such as quiz games, number guessing, and rock paper scissors, using tools like Visual Studio Code, IDLE, and Python, with a focus on coding fundamentals and problem-solving skills.

Full Transcript

[Music] hello everybody and welcome to another youtube video so in today's video i'm going to be sharing with you five python mini projects for complete beginners now each of these projects shouldn't take us longer than about 15 or 20 minutes to actually code out what i'm going to be doing is giving you kind of a starting template for these so i'm not starting with any code pre-written or anything like that in fact everything i'm doing here is completely from scratch i don't have any code on my other monitors or anything like that and the idea behind this is i'm going to show you my kind of thought process in creating these games explain to you why i've written the code that i did and kind of how it works and then that should hopefully give you guys a good idea how to go about extending these games and kind of customizing them to your liking now as i said these are for complete beginners when i say complete beginners i'm kind of referencing people that have a little bit of familiarity with python have maybe looked at the syntax a bit but aren't quite comfortable yet are still considering themselves beginners and kind of want some projects to work on and some i guess things that they can use to actually apply their skills rather than just looking at straight theoretical tutorials so anyways with that said i hope you guys are looking forward to this let's get into it after a quick word from our sponsor before we get started i need to thank the sponsor of this video which is alco expert algo expert is the best platform to use for preparing for your software engineering coding interviews and has the highest quality coding interview practice questions with 155 practice questions detailed solutions in nine of the most popular programming languages a feature-packed browser-based coding environment extensive test suites and conceptual overviews and code walkthroughs for each and every problem algo expert is the best resource to use to ace your coding interviews algo expert also has a data structures crash course coding interview assessments and a mock interviews feature i can highly recommend algo expert as a former customer myself and now an official instructor on the platform get started using algo expert today by clicking the link in the description and using the code tech with tim for a discount on the platform alright so the five projects i have for you and in the order in which i'm gonna be showing you them is a quiz game a number guesser game rock paper scissors choose your own adventure and then finally a password manager now these are going in the order of difficulty so the first one i'm showing you is the simplest the last one i'm showing you will be the hardest but the last one is still not going to be that hard if you're a complete beginner you should still be able to actually code it out and understand what's going on now if you guys want to skip to a certain project you don't want to go through one of them whatever there will be some timestamps in the description and kind of chapters on the video timeline so feel free to skip through to whatever you want and now what i'm going to do is quickly show us how we can set up our environment and then we'll get started working on this first project which is the quiz game all right so right now i'm using something called visual studio code this is known as an ide an integrated development environment you totally do not need to use this if you have this installed then you know how it works go for it but for most of you i'm going to recommend you something called idli so when you install python i'm going to assume you have python installed at this point in time what you're going to do is open up this app called idle if you're on windows you can search for it on the windows bar if you're on mac you can look for it in the spotlight search which is in the top right hand corner so open up idle again this is installed by default when you installed the kind of vanilla version of python and this is going to bring up something known as the interactive shell now this is not where you write your code i want to make that very clear a lot of people make the mistake of writing all their code here no don't do that what you want to do if you're using this is go to file press a new file and now you have the place you're actually going to be writing your code so the first thing i recommend you do is save this file so save it in a folder save it on your desktop wherever and name it something right name it like the name of the project quiz game uh choose your own adventure game whatever i would recommend you make new files for every one of the new projects that you are working on and so i'll just give give you an example here i'm going to save this as test.pi and now if i go in here and i type you know print hello just some basic python syntax the way i actually run this code here is i press run and then run module or alternatively i press the f5 key and then notice it's going to bring up this interactive shell it's going to print out and run your program and then you can go back here modify it save it and whenever you want to run it you press f5 or press run and then run module all right so hopefully that gives you gives you guys an idea how to set up your environment obviously feel free to download visual studio code as well leave a link to it in the description or use any coding environment that you're comfortable with and that you know how to use so right now have a python file open this is a file that's on my desktop it doesn't really matter where you put the file and the first thing i'm going to do here is start working on the quiz game so this quiz game the idea behind it is we want to ask the users a bunch of questions and then if they give us the right answer to these questions we'll kind of add one to their score then at the end of the program we'll print out what they got out of the number of questions so if there was 10 questions we would say hey you got you know 3 out of 10 or 7 out of 10 or whatever and maybe we'll even give them a percentage or something like that so let's get started the first thing i'm going to do here is use the print command or the print function i'm going to assume you guys are familiar with this but when you want to print something to the screen output something to the console you say print you put some value in here the value you typically put is a string a string is anything encapsulated in double quotation marks or single quotation marks and then this will be what is outputted so the first thing i'm going to do is just kind of welcome my users to the game i'm going to say welcome to my and then computer quiz so the specific quiz i'll go with this computer quiz please feel free to go with whatever type of quiz that you want all right now we've welcomed the user to our game let's just quickly test this out in vs code to run your code you press this little kind of run button right here you're going to see it should open up a terminal down here and then notice it says welcome to my computer quiz because the program just ran awesome so now what i want to do is ask the user if they want to play my game if they say no i don't want to play then we'll just immediately quit the game so to do that i'm going to create a variable i'm going to say playing is equal to and then i'm going to use this function called input now what input allows you to do is ask the user to start typing something in in the console so inside of input in here you put what's known as the prompt now the prompt is kind of what appears before the user can start typing so for example if you're asking the user for their name you may have the prompt be name and then colon and then maybe a space and then right here after this space the user could start typing whatever their name was so in my case i would put tim and then whatever they type after the prompt and then when they press enter that will be stored in playing so if i type tim and then i press enter now playing will be equal to tim because after the prompt that's what the user typed uh before they hit enter right hopefully that kind of makes sense and even if the user has a space they say like tim and then r all of this tim space r will be included in playing because this is all the stuff they typed after the prompt before they pressed enter so i'm going to ask them here do you want to play question mark and then i'm going to add a space here the reason i'm adding a space is because if i don't add a space then the user is going to start typing right on the question mark and that's going to be kind of all smushed together and it doesn't look nice and so we're going to add a space to make sure the user starts typing one space after the question mark all right so now if i run my program so i press the run button it says welcome to my computer quiz do you want to play notice the cursor is here and now i can start typing whatever i want when i press enter nothing's happening because we haven't done that yet we haven't configured that but that's kind of the basics that's how you get user input and just to show you here if i print out playing what this will do is give me whatever the value of this variable is so if i run this here it's welcome to my computer quiz do you want to play say yes and then it prints out yes right so pretty straightforward okay so now that we know if the user wants to play or not right because after this line is done we'll have something stored in playing we want to check if the user typed yes right and specifically if they didn't type yes we want to end the program so what i'm going to do is use something known as an if statement now an if statement allows us to conditionally check kind of or compare values together and see if something is true or false and so i'm just going to write out the kind of entire if statement then i'll run through it step by step i'm going to say if playing does not equal 2 so an exclamation point and then the equal sign and then i'm going to say yes then what i want to do is i want to quit the program and there's this function in python that you can use called quit this will just immediately terminate the program so what i'm doing is using if i'm writing what's known as my condition this is the thing that i want to check so i want to check if the variable playing which is what the user typed in is not equal to yes the reason i'm checking if it's not equal to yes is because if they typed anything other than the word yes i want to quit the program whereas if they typed yes i don't want to quit and so what happens here is we're going to compare whatever the user typed in with yes and since we're using not equal to if what the user typed in is not equal to yes this condition evaluates to a boolean which is known as true and then if this is true right so if whatever the condition is is true then whatever is indented after this colon here is going to be run so hopefully that makes sense i won't go too much more into the syntax i assume you guys can probably figure it out yourself but the idea is you put a colon and then all the stuff you want to happen when this condition is true you indent here and an indent is kind of four spaces i would recommend you use tabs rather than kind of going one two three four you'll get some issues with your indentation if you try to do spaces and tabs together so anyways let's just see this now uh let's run this program okay i'm going to say welcome to my computer quiz do you want to play i'm going to type yes and well the program is going to end regardless because we're not doing anything after this if statement but if i go here and i print okay exclamation point and then let's play smiley face um oops okay i need to fix my quotations here yeah okay that's all good let's run this now it says welcome to my computer quiz do you want to play i'll type yes and it says okay let's play right and then it gives a really bad smiley face that i need to fix and if we run this one more time and then this time we type no notice that it doesn't say okay let's play because this condition was true and so the program quit alright so that's about if statements hopefully that all makes sense we're going to be using a lot of if statements in this video so now we say okay let's play what we want to do is ask the user their first question and so what we're going to do is the exact same thing we did when we were asking the user if we want to play we're going to say some variable i'm just going to call it answer because that seems to make sense is equal to and then input and then i'm going to put whatever the question is i'm going to say you know ask something about a computer i'll say what does cpu stand for question mark and then what i'm expecting is that the user is going to type in the answer right and so what i'm going to do is just add a space here to make sure that again the user's not typing right beside the question mark they have a little bit of space and now what i want to do is check if the user's answer is equal to the correct answer so i'm going to say if answer is equal to and then i need to type out what the actual answer is now in this case this is central processing unit and i think i spelt processing correct obviously you're going to want to make sure your answers are actually spelled correctly because even if the user types in central processing unit but they like forgot the g or they spell something wrong or they have like a capital p they're going to have the question marked as incorrect because the answer has to match exactly with what the user typed it okay so now we have a colon and now we're saying okay well if the answer was equal to central processing unit what do we want to do i'm going to print that they got it correct so i'll say correct like that and notice i'm using single quotes and double quotes kind of interchangeably it doesn't matter which one you use so long as you're consistent with the starting and ending quote awesome so let's just run this now and see if this works so i'm going to press run it says welcome to my computer game do you want to play yes okay let's play what does cpu stand for central processing unit and then it gives me the the output saying correct now if i run this again do you want to play yes okay let's play what does cpu stand for i type in just cpu it doesn't give me anything because well this was not true sweet okay so now the thing is though if the user gets this wrong i want to tell them that they got it incorrect right we need some output saying them saying hey no that was not correct and so what we're going to use now is what's known as the else statement so whenever you have an if statement like this and you are checking if something is equal to something else and that's what the two equal sign is doing or you have some condition here if this condition here does not evaluate to true you can put this else statement here which means if this is not true whatever's in the else statement will run so if i go here and i say print incorrect exclamation point now if this is false so if the answer does not equal central processing unit then we will print out incorrect if we type anything doesn't matter just so long as this right here that we typed out is equal to false whatever's in the else here will end up run so let me just show you what i mean and then we can talk about this a bit more so let's run do you want to play yes okay let's play what does cpu stand for central processing unit and then it says correct and oops i i should have typed in the incorrect one but that's fine let's just type in no and then notice it gives me incorrect and if i ran this one more time type yes and i type some other random thing it still gives me incorrect so if i type anything other than central processing unit the else statement runs again the syntax for the else statement is you write else you do a colon and then any stuff you want to run you do indented after the else and you could do multiple things as well i could do another print statement and then both of these print statements would run uh if we got this question incorrect sweet okay so now we have our first question and now what we can do is kind of just copy this to do the rest of our questions right so i'll copy this uh one more time i'll do four questions for my quiz please feel free to do more and it's totally fine if we want to leave this answer variable the same i don't need to change this to be something else we could if we want to but since we are done using the answer for this question after this if statement it's fine if we use the same variable to store the answer for our next question so now what we're going to do is we're going to kind of remove all of our answers and questions and we're going to type in well new answers and new questions and i'll show you some more things that we can do here in kind of some fixes and all that as we go through but let's just get our questions done first all right so now my next question i'll say what does gpu stand for question mark and then this will be and i'll copy this graphics processing unit okay so let's go graphics processing unit like that i hope that's correct and then the next question we can ask um i'll just do a bunch of acronyms what does ram stand for question mark this will be random access memory like that okay and then lastly we can say what does psu stand for question mark and we'll just say power supply like that sweet so now we've got all of our different questions here and we're kind of printing out whether we got them correct or incorrect so let's just quickly test this out let's make sure this is all working so uh do you want to play yes what does cpu stand for central processing unit what does gpu stand for notice i didn't add the space here and since i didn't add the space you're going to see when i start typing here that's kind of smushed with the question mark so i'll say graphics processing unit what does ram stand for random access memory okay what does psu stand for let's just type psu and then notice it tells me incorrect so i'm going to start by fixing these spaces here you guys saw what happened when i didn't add the space for the input so now it should be all spaced out properly sweet so now we've got this all working hopefully you guys are all familiar with this if and kind of l syntax now it just needs to be in this structure whenever you have a colon typically in python the next line after that does need to be indented if i did this and like i didn't indent this line here you can see we're getting this red highlight and it's the reason we're getting that is because the indentation is all messed up this is supposed to be indented after we have the else statement in a small note you can only have the else statement after an if statement right so i can't just randomly come down here and put an else statement it needs to come after an if statement appears right so hopefully that's clear okay so now the one thing that i want to show you though is that we might be getting some kind of weird results from our program that we don't expect so i'm going to run my program and say do you want to play i'm just going to type yes with a capital y and notice when i do that it doesn't actually start my program right it immediately quits and the reason for that is whenever you have a capital that is different than lowercase right so if you have yes that is not equal to yes these are different strings and so if we want to check if the person's answer regardless of the case right if they have a capital y or capital e or a capital s or something or you know multiple capitals if we want y cap or capital y capital e lowercase s um to be valid and to allow the user to play we need to do something now there is this method in python called dot lower and what dot lower does is it takes whatever text we type in and it just makes it completely lower case so if i go here and i print you know tim is great like that and then i say dot lower and actually let me do this in another way that's not as confusing let me say text is equal to this and then i say text dot lower what this will do and make sure you have the parentheses by the way is it will convert all of this text to lowercase so i just run my program here and we have a look at our terminal notice that uh wait oh i have to type something let's just type that it says tim is great all in lower cases and so we can use this here to convert all of the answers that our user types in to lowercases so i can say playing.lower and then if the user typed in something with capitals we'll just all be lowercase and that way if they type yes with any different casing it will still evaluate to true because we're converting it to lower now in the same fashion there is something called upper if you say dot upper it will convert everything into upper cases and so then what you would do if you're using dot upper is you would make your answer in complete upper cases because you know you're always going to be converting anything lowercase to uppercase so hopefully that's clear but we're going to just throw lower on here to all of our answers so i'm going to say lower i'm going to say lower i'm going to say dot lower going to say dot lower and alternatively if you didn't want to do it this way you could actually just do it at the end of this input here you could say input dot lower and then you could just remove this because now your answer is already converted to dot lower so you don't need to convert it kind of in this condition right here okay hopefully that's all clear but yeah that's just taking your answer converting into lower case and then you're checking if the lowercase answer is equal to well the lowercase answer you actually have all right so let's rerun this i'm going to open up my terminal i'm going to run do you want to play i'm going to type yes with a capital y notice this works now and now i'm going to do some capital so central processing unit that works right gpu graphics processing unit and then you get the idea i won't do the rest of them okay so the last thing i want to do here is implement some notion of score right we want to be able to tell how many questions our users got correct so what i'm going to do is make a variable here at the top of my program i'm going to say score is equal to 0. this is going to allow us to keep track of how many correct answers they have now all we have to do here since we define score equal to zero is every time the user gets a question correct we just need to increment square so add one to score so inside of this if statement here because this is if the user got it correct right i'm gonna say score plus equals one what that says is okay take the value of score and add 1 to it that's equivalent to saying score is equal to score plus 1. so hopefully that's clear but that's a way that you can just add 1 to the variable and so if we add one to score every time we get something correct that means that at the end of our program we'll have some number right we'll have two three zero whatever however many questions we got right we can then use that to display how well the user did so i'm going to just say score plus equals one i'm going to do this inside of all of these if statements here okay and now we've added one to score so now what i can do at the very end of my program once we're done of our questions is i can say you got and then i need to use a plus sign this is a concatenation operator i'll discuss this in a second score plus and then questions correct exclamation point but i need to convert this to a string so let me go through what i just did here okay so i said you got i did a space notice i manually added the space here i then had a plus sign and then i said string score and then plus questions correct so the reason i'm doing this string here is because score is a number right score is an integer it's not a string and so if i tried to do something like you know tim plus one well this doesn't really make much sense right because i'm trying to add a number to a string and like how do you add one to text that's just an undefined operation that doesn't exist so what i need to do instead is convert this one to a string because now that i have two strings when i add them together what i get in python is tim1 right they kind of get combined and so that's what i can do i'm going to convert this score here into a string so then when i add it to the other strings that i have here it's valid this operation works and i'm not getting some issue popping up okay and then i'm adding the questions correct so i'm kind of putting this string score in the middle of the string right you got whatever the number is questions correct okay so let's run this and you want to play yes let's say let's cpu stand for central processing units okay graphics processing units okay psu ram and it says incorrect you got two questions correct right now it's giving me how many questions i got correct and so the very last thing we can do here is we can copy this line and we can give them kind of a percentage right like you got 50 or you got whatever percent and the way we do that is now we're just going to take our score we're going to divide it by the number of questions that we have is 4 and then we're going to multiply all this by 100 right and if we want to be extra clear here what we can do is put parentheses around this score over 4 to make sure this operation happens first before we multiply by 100 but you'll see if we did it the other way around we didn't add the parentheses it would still work fine because we would do the division before we did the multiplication but anyways we're going to say now instead of you got questions correct we're going to say you got and then we're just going to add a percent on here now notice i'm not doing a space and since i'm not doing a space it's going to be whatever this number is and then plus and then the percent sign so it'll come right after and then we can do a period so now we've calculated the the percent again just taking the score dividing it by our number of questions which is 4 and then multiplying it by 100. now note here if you change the number of questions you got to change this number right so let's go here and let's run this and let's go to our terminal yes we'll play i'll just type something random okay random access memory correct and then power supply and then it says you got 50 you got two questions correct and with that that is going to wrap up our first python mini project so i know i went really slowly through this and really explained everything in depth that's because this is the very first project i'm trying to make sure this video works for everyone regardless of your skill level and now i will go a little bit faster i won't re-explain a lot of the syntax that i've already explained now as we move into the new projects just anything new that i kind of come across that we use i will explain but this is our first project this is the quiz game there will be some code that has or there will be a link sorry that has this code in the description if you want to download this yourself but i would highly recommend you modify this you know change around maybe add like more than one point for questions that are worth you know more than one point that are more difficult or something like that right and you guys can do this as you please regardless that is the quiz game now we're gonna move on to do a number guesser i think this is the one i was saying i was gonna do second so this one is pretty straightforward but what we're gonna do is generate a random number and we're gonna track how many times it takes the user to guess this number and so what i'm going to do is zoom in a bit here so that we can see our code the first thing i'm going to do is import this module in python called red alright so first thing to mention here is that this right here is what's known as a module so when you import random you're importing the random module now this just lets you use all of the functionality that's kind of in here this is default this is installed by with python by default you don't need to install it or anything like that in quick note there is modules that are built by you know people like me or other developers out there and you can import them but you have to install them first this one is just built into python by default and so no installation is required anyways let me show you how to make a random number so there's a few different ways to do this but the two simplest ways are to do random dot and then rand range then you're gonna do an open and closing parentheses and let me get rid of the print statement so we can see this better for right now and here you're gonna put the start and then the stop of the range for your random number so you would do something like negative 1 if you wanted to start the range at negative 1 and stop at 10 excuse me and then what this would do is generate a random number that goes from negative 1 to 10 but does not include 10. so that's very important the number you put here is the absolute upper bound you cannot have the number 10 be generated if 10 is here if you wanted the range to generate a number between negative 1 and 10 you'd have to put 11. again i don't know why they do that there's just some things in python that aren't necessarily intuitive for beginners but with this is 11 it's not going to generate 11 it will generate up to 10. so make sure that's clear now there's another thing you can do here if you want the range to just start at zero you can say random.rand range and just put the stop if you just put one thing here what this will do is generate a random number between zero and this number minus one so up to ten and yeah there you go that's how that works okay so let's do something from negative 5 to 11 and let's say r is equal to random.randrange and let's just print r okay so let me run this and we'll look at our thing here okay run and notice we get a five now if i run this again we're getting a negative three i run a bunch of times we get a bunch of random numbers you see this is random and there you go that's working we got a nine we can just round a bunch of times we got a 10. notice we won't get 11 if we do this sweet so we're getting a random number so that's one way another way to do this is with a function called randint now rand int works the exact same way as rand range except now it will include 11. so the upper bound range now includes the number that you typed doesn't go up to but not included so now if i do negative 5 to 11 11 will possibly be generated so if i run this now uh we get 6 right and we if we keep running it we might see that we get 11. um okay i'm not this could take a while there you go so we do get 11. so that works okay sweet uh and same thing here if you decide to not include the start it will just generate up to and including this end number that you put right here so that's how you make a random number so what we want to do is generate a random number so actually let's let's leave this here let's say random underscore number and then we want to ask the user to guess this number and every single time they guess it we're going to tell them if they were above or below the number so that they can do it in like a reasonable number of guesses especially if we make this number like really large right so the first thing i'm going to actually ask the user is how large of a number they want to generate so we'll assume it starts at 0 and then we'll ask them to type in a number and we'll generate up to that number so i'm going to say let's say top of range is equal to and then input and we'll say type a number won't even tell them what it's for we'll just say type a number okay so now they're going to type a number so what we actually need to do here is we need to make sure that this thing they typed in here is a number because if the user types in like hello or tim or some random string something that's not a number then we can't use that right and we also need to make sure the number they type in is greater than zero so i'll show you how we do that i'm going to say if the top of range dot is digit okay and then i'm going to do an if statement inside of this if statement i'm going to say if the int and actually we're going to do this we're going to say top of range is equal to int top of range and let me pause here and explain what i'm doing so first of all you can make a variable using underscores when you want to have multiple words it makes a lot of sense to make the name with underscores so like top underscore of underscore range you can't have a variable that's like top range that won't work you need to have it connected you can't have like two separate words like that anyways this is equal to input the user is going to type something in now by default when the user types something in it's going to return it to us with double quotation marks so it's going to be a string so even if the user types in like 25 it's going to be returned to us like this and this here for python is not considered a number it's not considered an integer it's considered a string and so we need to convert this 25 so that it looks like this so that's actually a number and the way you do that is you use this function called int so you surround the string with int and then it will convert this string into its numeric representation so it will give us 25. however if you try to convert something that's not an actual integer into an int it's going to fail you're going to get an error and so we need to make sure that what the user typed in is a digit before we try to convert it into an it and the way you check that is with this is digit method so i say if top of range dot is digit what is digit will do is return to us true if this is a number otherwise it will return false and so if this right here is true we will convert top of range into an integer so top of range is equal to int top of range then we will check if top of range is greater than zero so we'll say if top of range is actually we're going to say less than zero less than or equal to zero specifically then what we will do is we'll print out please type a number larger than zero next time and then we'll just quit so we'll tell them what they did wrong and then we're just going to quit the program right there otherwise if we make it through all this we're good but one thing we need to do here is we need to put an else and we need to put quit and we need to put a print statement that says please type a number next time so let me run through this what we're doing is checking if it is a digit if it's not a digit so in the else statement we need to tell them hey you got to type in a digit it doesn't work if you don't type in a number right and then we quit now if that works if it is a digit we convert it into an int we make sure it's greater than zero if it isn't then we tell them hey you got to type in a number and then we quit but if we make it through all of this and we don't quit so we've now converted the number to an int we can now use that number to generate our random number so we can say randomnumber random.randint and then we can put top of range as our variable for generating that random number and we'll now generate up to whatever number they typed in sweet so now that we have that let's just print out the random number and let's just test this and make sure it's all working so i'm going to run this type number let's type five and we got one issue rand it missing one potential argument b okay so this is my fault i was saying when we used rand int we could just include the top of the range that's false we need to include the bottom of the range as well so i'm going to put 0 there and now this should work so let's run this and let's type a number let's type 5 and there you go we generated a random number which was 4. if we run this again type 5 we get 3 you can see this is indeed working sweet so now that we have our random number we want to keep asking the user to type in a guess for the number until they get it correct and so i'm going to use a while loop here and i'll explain how this works in a second i'm just going to say well true now what this means is okay we're going to do whatever is indented after this while loop here after the colon while this condition whatever's at the top of here is true so right now if we just decided to like print tim this would happen infinitely this loop would never stop unless we actually like manually close the program the reason is because there's no way for this to end right i say while true well true is always true and so we're just always going to print 10. however there is this keyword it's called break and what break will do is immediately stop the loop as soon as this line of code is executed so what we can do is use this break keyword to break out of the loop stop running the loop as soon as the user types in the correct number so we're going to say while true this is the condition for the while loop we could do a real condition we could say something like wow um like input and actually we'll say like user guess is not equal to random number we could do something like that that would work as well but i want to show you using the break keyword so instead we're going to do well true all right so what we're going to do is we're going to start by asking the user to guess what the number is right that's the very first thing we do every single time we ask them we say okay make a guess so i'm going to say user underscore guess is equal to and then input i'm going to say make a guess call now same thing here we need to check if the user's guess is actually an integer right so i'm going to copy exactly what we just did right here and i'm going to paste it down below and i'm going to say okay if the and now instead of saying top of range i'm going to say user underscore guess dot is is digit then user underscore guess is equal to int of user underscore guess and then i'll even take this and we don't need to check if the number is less than zero that's fine uh we can just do this so i'm going to say and i'm going to get rid of this this quit okay let me explain this but what i'm saying is okay the user guess is equal to input make a guess they're gonna type in some number this comes in as a string we need to make sure that what they've typed in is actually a number if it is a number we'll convert it to a number we're all good however if it is not a number then we're going to say please type a number next time and we're going to use this keyword called continue now what continue will do is automatically bring us back to the top of our loop so it's a little bit different than break rather than ending the loop it just brings us back to the very top so if i did something down here like printed after continue if we hit this continue keyword this won't run we won't print we'll just go back up to the top of the loop and ask the user to make another guess and so that's what we're going to do however we're going to come down here now we're going to say if the user guess is equal to the random number we're going to print and we're going to say you got it you got it correct otherwise we'll say else print you got it wrong so if they didn't get it right they got it wrong obviously right whereas if they didn't type a number we'll just say please type a number next time and then we'll continue rather than doing this and telling them they got it wrong after they didn't even type a number in okay hopefully that makes sense we can test this out though and make sure it's working so save the program and run now type a number let's type a number let's say 10 okay make a guess we're gonna guess three and wow okay we actually got it that's great but notice that it's still asking us to keep making guesses and to quit this you can type control c on your keyboard if you get into an infinite loop the reason it's telling us to do that is because we didn't break out of the while loop right we said you got it but we didn't stop and to stop we need to use the break keyword so now you'll see if we do guess it we'll immediately stop looping whereas if we don't get it we will continue looping because the break keywords not here so let's run this now type a number let's just go up to five make a guess one you got it wrong okay we'll guess two you got it wrong three you got it wrong four you got it wrong five you got it sweet and then we exit the loop there you go okay so that's working fine now what i'm going to do is i'm going to keep track of how many times the user actually makes a guess so to do this i'm going to make a variable similar to what we had with score before i'm going to say guesses is equal to 0. and now every single time we start this while loop again i'm going to increment add 1 to guesses so i'm going to say guesses plus equals 1. so at the very top of the loop we'll increment guesses so the first time this runs guesses will be equal to one we'll go through all of this then we'll come back up to the top guesses will now be equal to two the user will now make another guess and now when we exit this while loop once this is done we're gonna print out how many guesses they got i'm going to show you a different way to do this this time i'm going to say you got it in and then we'll say comma guesses and then the string guesses so another way to print multiple things on the same line is to use commas so i'm going to say you got it in and then i'm going to say whatever the number of guesses is notice i don't need a space here whenever you have commas separating your different things that you're printing out it will automatically add spaces in between them and then notice here i didn't even convert this to a string and that's because the print statement is smart enough to say okay hey this is an int i'm going to convert this into a string for you and kind of automatically add it to this string so what we were doing manually before the print statement can just do for us and so this time we'll let the print statement do it uh this line here is completely equivalent to just having the uh the plus the space the string uh the other plus and the space right it's the exact same thing okay so let's go back to what we had and there you go we are all good now let's just run this and i am going to show you how we can tell them if they got it greater than or less than because i did tell you that we were going to do that okay so let's run this and let's say type a number let's go five make a guess one you got it wrong two you got it and then it says you got it in two guesses sweet all is working so now the last thing we want to do is tell the user if they were greater than or less than the number so that they can kind of narrow down their guesses and so rather than just telling them you got it wrong now inside of the else statement we're going to check if the user was above or if they were below there's a ton of different ways to do this i'm just going to do it this way i'm going to say if the user guess is greater than the random number then what i want to do is say print you were above the number exclamation point otherwise i'm going to say print and i'll say you were below the number all right so let's run through this we're just checking if the user guess is greater than whatever the random number is if it is we're going to tell them they were above the number otherwise if it wasn't greater than it must be less than and we're going to say you were below the number now some of you may have heard that statement if it wasn't greater than it must be less than you said no it could be equal to that's correct but the thing is up here we checked if it was equal to and so if it was equal to we would have gone into here we would not have hit this else statement so if we're in this else statement we know we must not be equal to the random number and so instead what we can do is just run this if statement that's inside of the else i'm going to show you a more elegant way to do this in one second but let's just run the program and see if this works okay let's run this type a number let's type 20 make a guess let's guess 10. you were above the number okay so now i don't have to guess below 10. so i'm going to guess 5 you are above the number okay it's less than 5. uh 4 3 2 1 you got it in nine guesses okay so anyways that did work but it was telling us whether we were above or below uh let's see if i can guess something that's actually i guess i couldn't have guessed anything below one so let's run this again let's type 10 let's guess one and then this time it is telling us we're below the number okay great so that is working okay so the one thing i want to show you here is how we can clean this up a little bit using something new that we haven't seen yet which is known as an l if statement so an l if statement is something that kind of happens after the initial if statement's checked so i'm just going to type this out and then i'll show you how this works so i'm going to say lf okay so now what i've done is i've made this code a little bit cleaner and the way i've done this is i've removed that kind of nested if statement that we had and i've now implemented an alif instead so what the life does is if the initial condition is not true it will then check another condition so it says okay if this is true we're going to do this we're going to skip all of this if this is not true we're going to check this if this is true we're going to do this and we're going to skip whatever else is after it however if this is not true then we're going to do whatever is in the else so we're going to check this if it's true we do this otherwise we check this if it's true we do this and otherwise if both of these things are false we do what's in the else and so that's just another way to do this rather than having what we have before which was the else and then all of this kind of indented in the else right this just cleans it up and small note you can have as many lf statements as you want so i could add another one like this if i wanted to do that but in our case it doesn't really make any sense to do that okay so that's actually it i'm not going to run the program just believe me this this does work and yeah that is going to be our number guessing game so i'll zoom out a bit so you guys can kind of see all of the code but that is how that works i guess there's not really much more to say about that and now we'll move on to the next one all right so now we're moving on to rock paper scissors now obviously you guys know how this game works what i'm going to do here is make it so that the computer keeps track of how many times the user gets it correct versus how many times the computer gets correct when i say corrects or i mean whoever wins rock paper scissors so the first thing we're going to do here is import random now small note here when you are importing modules it's typically best practice to do at the very top of the program i see some beginners import the module like right before they use it that's fine you can do that but it's just a better practice to have it right at the top so it's really easy to see what stuff you've imported and obviously remove it and then you can use it throughout the entire file whereas if i tried to use like random up here it doesn't work until after i've imported right so hopefully that's clear but anyways that's what we're going to do so what we need is we need two variables one for the user score and one for the computer score so i'm going to say user underscore wins is equal to zero and i'll say computer underscore wins is equal to zero as well all right now i'm going to have a while loop i'm going to say wow true and the first thing i'm going to do here is i'm just going to ask the user uh actually yeah i'll ask the user to input rock paper or scissors and then i will also let them type in q like the letter q and if they do q then we'll just immediately quit the program so let's handle that first let's say user underscore input is equal to input and i'll say type and then we can say rock slash paper slash scissors is scissors with uh with with two s's i think that's how you spell it okay rock paper scissors and well paper should be spelt correctly okay rock paper scissors or q to quit okay all right so now that we have that we will go down and we will check let me just zoom out so we can see this here what the user actually typed it so the first thing i want to do is i want to see if they typed in queue so i will actually convert this to dot lower in kind of the way that i showed you we could do it previously we'll take whatever the user types in and we'll just convert it to dot lower and actually instead of a period let me do a colon and let me add a space so it's not all smushed there okay so type rock paper scissors or queue to quit and now i'm going to say if the user input and this is converted to dot lower right is equal to q then what i'm going to do is i'm going to quit otherwise i'm going to check if they typed in rock paper scissors or if they type something else and now i'm going to show you how we can check if the user input is equal to more than one thing because previously i've been showing you how we can check if it's equal to just a string right but now i'll give you a little bit of i don't want to call it a hack but a little bit of a trick so that you can see if the user typed in rock paper or scissors all in one line rather than writing three if statements so i'm going to say if the user input is in and i'm going to use a list you guys probably haven't seen this before if you're like a complete beg

Original Description

Welcome back to another video! In this video, I will be showing 5 mini python projects for beginners. I'll be showing you how I would create a template from scratch. Using this template, you can keep building and practicing your programming skills. 💻 AlgoExpert is the coding interview prep platform that I used to ace my Microsoft and Shopify interviews. Check it out and get a discount on the platform using the code "techwithtim" https://algoexpert.io/techwithtim 📄 Resources 📄 Projects Code Download: https://github.com/techwithtim/5-Python-Projects-For-Beginners Download VSCode: https://code.visualstudio.com/ Fix Pip (Windows): https://www.youtube.com/watch?v=AdUZArA-kZw Fix Pip (Mac/Linux): https://www.youtube.com/watch?v=E-WhAS6qzsU&t=4s Fernet Cryptography Documentation: https://cryptography.io/en/latest/fernet/ ⭐️ Timestamps ⭐️ 00:00 | Introduction 02:09 | List of Projects 02:53 | Environment Setup 04:51 | Project #1 - Quiz Game 25:05 | Project #2 - Number Guessing Game 42:53 | Project #3 - Rock, Paper, Scissors 57:44 | Project #4 - Choose Your Own Adventure 01:09:53 | Project #5 - Password Managers (Most Advanced) ◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️ 💰 Courses & Merch 💰 💻 The Fundamentals of Programming w/ Python: https://tech-with-tim.teachable.com/p/the-fundamentals-of-programming-with-python 👕 Merchandise: https://teespring.com/stores/tech-with-tim-merch-shop 🔗 Social Medias 🔗 📸 Instagram: https://www.instagram.com/tech_with_tim 📱 Twitter: https://twitter.com/TechWithTimm ⭐ Discord: https://discord.gg/twt 📝 LinkedIn: https://www.linkedin.com/in/tim-ruscica-82631b179/ 🌎 Website: https://techwithtim.net 📂 GitHub: https://github.com/techwithtim 🔊 Podcast: https://anchor.fm/tech-with-tim 🎬 My YouTube Gear 🎬 🎥 Main Camera (EOS Canon 90D): https://amzn.to/3cY23y9 🎥 Secondary Camera (Panasonic Lumix G7): https://amzn.to/3fl2iEV 📹 Main Lens (EFS 24mm f/2.8): https://amzn.to/2Yuol5r 🕹 Tripod: https://amzn.to/3hpSprv 🎤 Main Micropho
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Tech With Tim · Tech With Tim · 0 of 60

← Previous Next →
1 A* Path Finding Algorithm(Visualization)
A* Path Finding Algorithm(Visualization)
Tech With Tim
2 Python Programming Tutorial #1 - Variables and Data Types
Python Programming Tutorial #1 - Variables and Data Types
Tech With Tim
3 Python Programming Tutorial #2 - Basic Operators and Input
Python Programming Tutorial #2 - Basic Operators and Input
Tech With Tim
4 Python Programming Tutorial #3 - Conditions
Python Programming Tutorial #3 - Conditions
Tech With Tim
5 Python Programming Tutorial #4 - IF/ELIF/ELSE
Python Programming Tutorial #4 - IF/ELIF/ELSE
Tech With Tim
6 Python Programming Tutorial #5 - Chained Conditionals and Nested Statements
Python Programming Tutorial #5 - Chained Conditionals and Nested Statements
Tech With Tim
7 Python Programming Tutorial #6 - For Loops
Python Programming Tutorial #6 - For Loops
Tech With Tim
8 Python Programming Tutorial #7 - While Loops
Python Programming Tutorial #7 - While Loops
Tech With Tim
9 Python Programming Tutorial #8 - Lists and Tuples
Python Programming Tutorial #8 - Lists and Tuples
Tech With Tim
10 Python Programming Tutorial #9 - Iteration by Item (For Loops Continued...)
Python Programming Tutorial #9 - Iteration by Item (For Loops Continued...)
Tech With Tim
11 Python Programming Tutorial #10 - String Methods
Python Programming Tutorial #10 - String Methods
Tech With Tim
12 How to Overclock a NVIDIA GPU
How to Overclock a NVIDIA GPU
Tech With Tim
13 Python Programming Tutorial #11 - Slice Operator
Python Programming Tutorial #11 - Slice Operator
Tech With Tim
14 Python Programming Tutorial #12 - Functions
Python Programming Tutorial #12 - Functions
Tech With Tim
15 Python Programming Tutorial #13 - How to Read a Text File
Python Programming Tutorial #13 - How to Read a Text File
Tech With Tim
16 Python Programming Tutorial #14 - Writing to a Text File
Python Programming Tutorial #14 - Writing to a Text File
Tech With Tim
17 Python Programming Tutorial #15 - Using .count() and .find()
Python Programming Tutorial #15 - Using .count() and .find()
Tech With Tim
18 Python Programming Tutorial #16 - Introduction to Modular Programming
Python Programming Tutorial #16 - Introduction to Modular Programming
Tech With Tim
19 Python Programming Tutorial #17 - Optional Parameters
Python Programming Tutorial #17 - Optional Parameters
Tech With Tim
20 Python Programming Tutorial #18 - Try and Except (Python Error Handling)
Python Programming Tutorial #18 - Try and Except (Python Error Handling)
Tech With Tim
21 Python Programming Tutorial #19 - Global vs Local Variables
Python Programming Tutorial #19 - Global vs Local Variables
Tech With Tim
22 Python Programming Tutorial #20 - Classes and Objects
Python Programming Tutorial #20 - Classes and Objects
Tech With Tim
23 Cool VBS Script to Prank Your Friends!
Cool VBS Script to Prank Your Friends!
Tech With Tim
24 How to Overclock an AMD GPU
How to Overclock an AMD GPU
Tech With Tim
25 Best GPU'S For Mining Ethereum (2018)
Best GPU'S For Mining Ethereum (2018)
Tech With Tim
26 Recursion and Memoization Tutorial Python
Recursion and Memoization Tutorial Python
Tech With Tim
27 Ethereum Mining Rig - Hardware Guide
Ethereum Mining Rig - Hardware Guide
Tech With Tim
28 Pygame Tutorial #1 - Basic Movement and Key Presses
Pygame Tutorial #1 - Basic Movement and Key Presses
Tech With Tim
29 How to Install Pygame (Windows 8/10)
How to Install Pygame (Windows 8/10)
Tech With Tim
30 How to Trade Your Cryptocurrency (Bitcoin, Ethereum etc.) For Cash!
How to Trade Your Cryptocurrency (Bitcoin, Ethereum etc.) For Cash!
Tech With Tim
31 How to Mine Ethereum 2018 - WORKING (Super-Easy)
How to Mine Ethereum 2018 - WORKING (Super-Easy)
Tech With Tim
32 Microphone Comparison - $10 Mic vs $150 Mic (Blue Yeti USB)
Microphone Comparison - $10 Mic vs $150 Mic (Blue Yeti USB)
Tech With Tim
33 Pygame Tutorial #2 - Jumping and Boundaries
Pygame Tutorial #2 - Jumping and Boundaries
Tech With Tim
34 Pygame Tutorial #3 - Character Animation & Sprites
Pygame Tutorial #3 - Character Animation & Sprites
Tech With Tim
35 Pygame Tutorial #4 - Optimization & OOP
Pygame Tutorial #4 - Optimization & OOP
Tech With Tim
36 OBS Studio Tutorial - Best OBS Settings
OBS Studio Tutorial - Best OBS Settings
Tech With Tim
37 Linear Search Algorithm - Python Example and Code
Linear Search Algorithm - Python Example and Code
Tech With Tim
38 Make Any Mic Sound AMAZING! (WITH OBS)
Make Any Mic Sound AMAZING! (WITH OBS)
Tech With Tim
39 Binary Search Algorithm - Python Example & Code
Binary Search Algorithm - Python Example & Code
Tech With Tim
40 Pygame Tutorial #5 - Projectiles
Pygame Tutorial #5 - Projectiles
Tech With Tim
41 Pygame Game - Mini Golf
Pygame Game - Mini Golf
Tech With Tim
42 Pygame Tutorial - Projectile Motion (Part 1)
Pygame Tutorial - Projectile Motion (Part 1)
Tech With Tim
43 Pygame Tutorial - Projectile Motion (Part 2)
Pygame Tutorial - Projectile Motion (Part 2)
Tech With Tim
44 Pygame Tutorial #6 - Enemies
Pygame Tutorial #6 - Enemies
Tech With Tim
45 Pygame Tutorial #7 - Collision and Hit Boxes
Pygame Tutorial #7 - Collision and Hit Boxes
Tech With Tim
46 Pygame Tutorial #8 - Scoring and Health Bars
Pygame Tutorial #8 - Scoring and Health Bars
Tech With Tim
47 Cloud Mining vs. Hardware Mining - 2018
Cloud Mining vs. Hardware Mining - 2018
Tech With Tim
48 How to Install Pygame on Mac OSX (Fast-Simple)
How to Install Pygame on Mac OSX (Fast-Simple)
Tech With Tim
49 Pygame Tutorial #9 - Sound Effects, Music & More Collision
Pygame Tutorial #9 - Sound Effects, Music & More Collision
Tech With Tim
50 Pygame Tutorial #10 - Finishing Touches & Next Steps
Pygame Tutorial #10 - Finishing Touches & Next Steps
Tech With Tim
51 How to Fade Your Screen in Pygame [CODE IN DESCRIPTION]
How to Fade Your Screen in Pygame [CODE IN DESCRIPTION]
Tech With Tim
52 How to Create a Button in Pygame [CODE IN DESCRIPTION]
How to Create a Button in Pygame [CODE IN DESCRIPTION]
Tech With Tim
53 Pygame Side-Scroller Tutorial #1 - Scrolling Background/Character Movement
Pygame Side-Scroller Tutorial #1 - Scrolling Background/Character Movement
Tech With Tim
54 Pygame Side-Scroller Tutorial #2 - Random Object Generation
Pygame Side-Scroller Tutorial #2 - Random Object Generation
Tech With Tim
55 Pygame Side-Scroller Tutorial #3 - Collision
Pygame Side-Scroller Tutorial #3 - Collision
Tech With Tim
56 Pygame Side-Scroller Tutorial #4 - Scoring and End Screen
Pygame Side-Scroller Tutorial #4 - Scoring and End Screen
Tech With Tim
57 How to Create A Message Box in Python - Tkinter
How to Create A Message Box in Python - Tkinter
Tech With Tim
58 Is Ethereum Mining Still Profitable - Is It Worth It (April 2018)
Is Ethereum Mining Still Profitable - Is It Worth It (April 2018)
Tech With Tim
59 How to Run MAC OSX on a WINDOWS PC (Clover Boot-loader)
How to Run MAC OSX on a WINDOWS PC (Clover Boot-loader)
Tech With Tim
60 Programming Problem #1 - Alphabet Soup (Beginner/Novice)
Programming Problem #1 - Alphabet Soup (Beginner/Novice)
Tech With Tim

This video teaches beginners how to create interactive quiz games, number guessing games, and rock paper scissors games using Python, with a focus on coding fundamentals and problem-solving skills. The projects cover topics such as input validation, game logic, and user interaction, and demonstrate the use of tools like Visual Studio Code, IDLE, and Python.

Key Takeaways
  1. Open IDLE and create a new file
  2. Save the file with a specific name and run the code using the run module or F5 key
  3. Use the print function to output text to the screen
  4. Ask the user for input using the input function
  5. Check if the user's input is correct using if-else statements
  6. Implement while loops for repeated user input
  7. Validate user input for game development
  8. Use the random module for number generation
  9. Apply mathematical concepts for game logic
💡 The video demonstrates how to use Python to create interactive games and quizzes, and how to apply coding fundamentals and problem-solving skills to real-world projects.

Related Reads

📰
On July 1, 2026, arXiv will spin out from Cornell University, its home for the past 25 years, to become an independent nonprofit organization. Major funding support from Simons Foundation and Schmidt Sciences. Ditching the red for their website. [N]
arXiv is becoming an independent nonprofit organization after 25 years at Cornell University, backed by major funding, which will impact the future of research and academia
Reddit r/MachineLearning
📰
CS-NRRM™ Official Publications: Paper 1 and Paper 2 Are Now Available
Learn about the CS-NRRM's official publications on a 12-year longitudinal human observation archive and its significance in research and development
Medium · Data Science
📰
Found a potential mistake in an ICLR 2026 blogpost [D]
Verify a potential mistake in an ICLR 2026 blog post and learn how to effectively report errors in academic publications
Reddit r/MachineLearning
📰
Rebuttals Move Peer-Review Scores, but Initial-Review Structure Bounds the Movement
Learn how author rebuttals impact peer-review scores and the factors that influence their effectiveness in ICLR 2024-2025, using LLMs for measurement
ArXiv cs.AI

Chapters (8)

| Introduction
2:09 | List of Projects
2:53 | Environment Setup
4:51 | Project #1 - Quiz Game
25:05 | Project #2 - Number Guessing Game
42:53 | Project #3 - Rock, Paper, Scissors
57:44 | Project #4 - Choose Your Own Adventure
1:09:53 | Project #5 - Password Managers (Most Advanced)
Up next
Docker is the Bottleneck — Dockerless Fixes AI Coding Agent Training
Prompt Engineer
Watch →