How to Make A Simple Game in Python (For Beginners)
Key Takeaways
The video demonstrates how to create a simple text-based game in Python using tools like IDLE and Pygame, covering concepts such as user input, conditional statements, and game development. It provides a step-by-step guide on how to make a simple game, including downloading and installing Python, creating a new file, and writing code to get user input and calculate scores.
Full Transcript
Hey guys, and welcome back to another YouTube video. So, I just wanted to start it off uh and apologize that I haven't been active for the last month or so. Um really there's not too many excuses I can make for myself other than I've been extremely busy and I really haven't found the motivation to sit down and make a video on my computer. Um now, I apologize to you guys. I know a lot of you have been subscribed for a while and you've been waiting for new videos. Um but I'm trying to get back into the flow of things now and I should be coming out with videos, I'm hoping at least once a week. So, right now I've I'm sitting down and making a video and I'm making it on another Python tutorial. Now, in this case, I'm going to be showing you how to make a really simple game. Now, the reason I'm doing this is because on some of my other Python videos, I got a really uh a large amount of support. I'm really thankful for that from you guys. I've been getting a lot more views on them, and a lot of you guys are really enjoying them. So, I figured I'd make some more. Now, this one is directed more towards beginners, um people that are really just starting off with Python. I'm not going into any graphics in this. It's not going to be a GUI. um anything crazy like stuff I've done before. It's just going to be a really simple textbased game that you can show your friends, you can show your family, and you can even maybe play by yourself. Now, in this case, I'm going to be making a game. It's going to be kind of a quiz on myself. So, I'll show you a quick example. I've got one open here that I made earlier. You can see, hi, welcome to the Tim quiz. Try to get as many questions correct as possible. Question one, what is the name of my YouTube channel? So, I'm going to answer it correctly. say text with Tim like so it gives us a little feedback says correct what is my age well you guys should know I'm 17 put 17 in there what is my favorite sport now I'm going to answer this one incorrectly I will tell you what it is after obviously um what is my favorite sport I'm going to do let's say um football like that incorrect what is my favorite food I'm just going to say sushi that's incorrect as well all right so you can see it says thank you for playing you got two questions correct you got at a 50% mark and it says nice, you passed barely, but we still did pass. And that is uh a really simple game and that's going to be something that I'm going to be showing you guys how to make right now. So, first thing we want to do is if we don't already have Python installed, go ahead and do that. To do that, uh just go Python uh on Google. It'll bring you up on the website here, python.org. Downloads. Download Python 3.6.5. Really straightforward, really simple. Do that. Once it's downloaded, uh, in your little search bar down here in Windows, you can click IDLE. So, just type that in. It's going to pop up. It'll give you a little console. It looks something like this. Now, you're going to click file, new file. There you go. Your screen should now look like mine, and you're ready to get uh running with Python. So, I did that quickly, but that's all right. You guys should be able to follow along. So, I'm just going to click control S here, and I'm going to save this. Uh, we'll say simple game two because I already did one earlier. Um, and let's just get started right away. So what I want to do is I first want to start by kind of greeting our uh user. So I want to say hello, welcome to and we just did a Tim quiz so maybe let's just do like trivia. Welcome to trivia like that. All right. And we'll say underneath here we're going to do a new variable. In this case we can say ans which stands for answer. Going to put input. I'm going to explain this after. Just follow along for right now. I'm going to say, "Are you ready to play?" Like so. I'm just going to give the answer I'm expecting. So, either yes or no, like that. All right. So, we just start off with a really simple print statement. If you guys don't understand any of this that I'm doing right now, I do have some really basic Pygame tutorials that you can go ahead and follow. Um, they're just on my channel. I'll leave a link to them up in the top right here and in the description down below. Uh it'll be in the form of a card if you want to click on it on the actual video right now. If you guys are interested in more advanced tutorials, this one's way too easy for you. Uh go ahead and check out my Pi game tutorials. Uh it's how you make a graphical game in Python. Little bit more advanced, but it's more rewarding and you actually get to see some physical stuff on the screen. Again, card right now, link in the description down below. Okay, so we say input. And what this is going to do is it's going to allow the user to type in after this line either yes or no. So, I'm just going to put a colon in here. So, that gives them a little space to type. Um, are you ready to play? Yes or no? Now, I'm just going to go a little if statement. I'm going to say if ans dot lower and explain what that does again in a second. Equals equals yes, we're ready to play. We can go ahead and continue typing our stuff in here. So, what this little dot lower is that I put here is it's actually a string method. And what it does is it turns all of our input into lowercase. So right here, whatever the user types is going to be stored in this variable ANS. And then for example, if they were to type yes in all capitals and we were to compare just ANS equals equals yes. Well, it doesn't equal lowerase yes equals uppercase yes. So this is going to be false. It's not going to let the user play. So by putting it lower, it changes that into lowercase letters. So we can then compare it against this and make sure that we don't get people typing yes or um maybe have a capital Y at the beginning of yes um and not being able to play. So we'll get right into question one. So in here I'm just going to actually up top let's do this. I'm going to define a new variable. I'm going to call it score. Going to set it equal to zero. Going to say total Q. So that's going to stand for total questions. And in this case we're just going to do four just so it doesn't take us too long. Obviously you guys can do a lot more if you want to do that just by following the format. that I'm about to show. So now we're going to ask the next question. So we're going to use ans again for answer. We're going to say input. Then in here we're going to say question one. And what's a good question we can ask? We can say um what is the best programming language? Now obviously this is very subjective. Uh you can answer any language you want in here. In this case I'm just going to put Python just cuz I can't really think of a good question right now. Um, but if you were to really do a trivia one, you might want to do something that's more fact-based. All right, we're going to say again if ans equals equals Python. All right, but we're forgetting something because someone might use a capital P for Python. We want to put lower in front of here. What we're going to do is we're going to add one to the score. So score plus equals 1. And then we're going to go ahead and we're going to print correct. So you don't have to tell them if they got it correct or not. I like to do that um just so they know which ones they're getting wrong. But if you don't want to and you want to make it kind of a bit harder for them to play again and again, try to get perfect, you don't have to tell them if they got it correct or not. And you would just leave out the part that I'm about to type right now, which says else print incorrect like that. So all you would do if they got it correct is you'd go score plus equals 1. And then you move on to the next question. Now for the next question, it's really straightforward. All I'm going to do is copy this, paste it down here, and then I'm just going to change the question and the answer. So, question number two, let's do maybe a more fact-based question. Let's say, what is 2 + 8 + 9 - 1. Now, who can do that the fastest? All right, so I know the answer. The answer is 18. So, we're going to do that. Now, the only thing is I don't want to put this lower method anymore because I'm assuming the person is going to be typing uh numbers. So, there's no point in putting lower. And the reason I'm putting quotes around my number here is because anytime anyone inputs anything in here, even if they type in, for example, 18 or like 187, it's going to come in as a string data type. Um, and I don't want to be checking number against string, right? So, I'm just going to keep it in quotations like this. All right, we're going to go down again. Same process. paste that down there. Question number three this time. Now for question number three, let's change this up a little bit and we're going to say um h what's a good question we can put down here. Okay, this one's good. What is better? A 1050 Ti or a 1060? Now, these have to involve graphics cards. So, I'm just going to give a little thing in here just so people know that we're dealing with graphics cards. Um, it's not just some random thing. So, if you don't know the answer to that, um, it's pretty basic, but I'm just going to put in here the answer is 1050Ti. And then again, we just keep correct incorrect. And we'll go ahead, we'll do another one. And this will be our last question just so I don't bore anyone too much. Number four. And we'll say, what should the question for number four be? What's a good trivia question? Let's see here. You can say, who came second in the Stanley Cup finals? Believe that's how you spell Stanley Cup. Maybe not. Anyways, uh in this case, I'm just going to give the option. I'm just going to put in here. We're going to say the Knights. I think it was the Las Vegas Knights, believe so. And then people are able to type uh obviously they might not type knights. They might type something else, but for the purpose of this tutorial, I'm just going to put Knights um because that's the answer that I would type in here. Now, if you wanted to, for example, give someone the option to be able to type two different answers and have that correct. Um so maybe you wanted them to be able to type Nights or you wanted them to be able to type Las Vegas or Vegas. The way that we would do that is we're just going to copy this here. I'm going to put or I'm going to puttrl +v. I'm say ants. Equals. In this case, I'm going to say Vegas. Now, what this allows us to do is it says if the answer is nights or the answer is Vegas, we're going to say that's correct. So, if either one of those are typed typed in, then that's the correct answer. And you can do that for any of the things like this. If you wanted to go maybe three answers, you would just continue or and then do the same process um for whatever the other answer would be. All right, so now that we've done that, I'm just going to test this to make sure everything's working. Okay, we say, are you ready to play? Type yes. What is the best programming language? Well, obviously we know that it's Python. What is 2 + 8 + 9 - 1? Now, in this case, I'm just going to type in the wrong answer. Let's say -9. All right, incorrect. What is better, a 1050 Ti or a 1060? That's graphics card. So, in this case, 1060. Incorrect. Oh, it's cuz I put the wrong card in the the answer slot. Don't worry, I'll fix that in a second. Who came second in the Stanley Cup finals? Vegas. There we go. Correct. Great. So, everything's working except this one just cuz I put the wrong answer in like me. Time 60. Now, that's all great, but what I want to do is at the end of this program, I want to print out how well they did in total. So, it's okay for four questions. Um, they probably know how many they got right and how many they got wrong. If you had a lot of questions, maybe like 20 questions, then we want to give them kind of like a mark. So, in here, I'm going to say print thank you for playing and then we're going to say comma uh actually comma here you got and then little space a comma now which is outside of the quotes and this is where we're going to put our score. So score and then questions correct just like that. So thank you for playing you got score which is going to be our score. So like 2 3 0 whatever questions correct period after this. Now I want to print out their mark. So in order to figure out what their mark was the percent they got what we're going to do is a really simple math calculation. So I'm just going to say mark is equal to and I'm going to put brackets because we need to do a little bit of order of operations here. We're going to say score divided by total questions and then multiplied by 100 just like that. And then again I'm going to print down here. I'm going to say print mark, mark like that. And then after this I'm going to say print goodbye like that. So let's go ahead and test this out. Hello, welcome to trivia. Are you ready to play? Yes, I am. What is the best programming language? Python. Correct. What is 2 + 8 + 9 - 1? 18. What is better, 1050 TI or 1060? So, I'm going to answer this run wrong and just put a 1050 TI. Incorrect. Who came second in the Stanley Cup finals? We'll put the Knights. Although, I just realized we need a K for Knights. I I am okay at English, guys. Don't worry. All right. So, thank you for playing. You got three questions correct. And our mark was 75. Goodbye. Now, there's a few things I want to fix here. Obviously, knights needs a K like that. Sorry about that. I'm sure a lot of you were screaming at uh the screen when you saw me type it like that. And then we're also just going to get rid of these spaces here. So, after it says you got and then questions because when we put the comma here, it automatically is going to put a space before and after our variable. So, same thing with mark, we can get rid of the space. And also, I want to add um the percent sign. So, to do this without having a space, it's going to say mark plus. And in this case, we're now going to have to put string for mark. And we're going to add a percent sign like this. And you'll see how that looks in just a second. All right. So, let's go ahead and check this out one more time. Are you ready to play? So, I'm just going to show you what happens if I click no. If you say no, it says, "Thank you for playing. You got zero questions correct. Mark, 0%. Goodbye." Um, obviously because your score is zero. And then if we click F5 and we click yes, say, "What is the best programming language?" In this case, we say Python. What is the answer to this? 18. What is better? In this case, I'm going to get it wrong again. 1050 TI and Vegas. Correct. Thank you for playing. You got three questions correct. Mark 75%. Goodbye. Now, if you wanted to, you could do a little final touch here. So, once I said no, it still went ahead and said thanks for playing. You got whatever. If we don't want it to say that, all we have to do is highlight all this and just click tab. because now we're indented into this little if statement here. So if we said no, it's just going to end the program right away. It's not going to bother um saying the rest of the stuff. Although we might still want it to say goodbye. So if we unindent goodbye, what happens here is once we get through this if statement. So after we've done all this, it's going to say goodbye. If we don't ever end up getting inside of this if statement because, well, it wasn't yes, then it's just going to print goodbye like that. All right, so that's pretty much been it for this uh video. just been a really simple uh explanation and kind of tutorial on how to make a really simple game text based. Obviously, you guys should be a lot more creative than I am and come up with some good questions, stuff that'll actually be entertaining to play. Um, you could do a quiz about yourself. You can do something like this and it's really neat way to kind of start learning how to program and it's a cool game. You could show your parents, you could show your friends, uh, and test how well they know you or test how well they know a certain topic or something like that. So, if you guys enjoyed the video, please make sure you leave a like and subscribe. I'm planning on doing more videos like this. So, if you guys enjoy these, let me know in the comments down below and I'll be sure to make some more. I'll see you guys in the next YouTube video. [Music]
Original Description
In this video I explain how to make a simple game in python. The game that I will be creating is very simple and is for beginners. Making games is a great and fun way to learn how to code and is something cool that you can show your friends and family.
Pygame Tutorials: https://www.youtube.com/watch?v=i6xMBig-pP4&list=PLzMcBGfZo4-lp3jAExUCewBfMx3UZFkh5
Basic Python Tutorials: https://www.youtube.com/watch?v=OFrLs22MDAw&list=PLzMcBGfZo4-mFu00qxl0a67RhjjZj3jXm
Want To Support This Channel?
Bitcoin: 1PbkAYLFaJBgjbKn2ptGyBz65xWN8hJgBU
Ethereum: 0xdd42dbbdba60f7163fc7a840e189474b6e8bfcad
Ripple: rD4arM9CVjQWqi8f1kxdpCgkCgEkqBgtud
Please leave a LIKE and SUBSCRIBE for more content!
Tags:
- Tech
- Tech With Tim
- Crypto
- Programming
- Coding
- Pygame
- Python Tutorials
- Python Game Making
- Simple game in python
- How to make a simple game in python
- Beginners
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
A* Path Finding Algorithm(Visualization)
Tech With Tim
Python Programming Tutorial #1 - Variables and Data Types
Tech With Tim
Python Programming Tutorial #2 - Basic Operators and Input
Tech With Tim
Python Programming Tutorial #3 - Conditions
Tech With Tim
Python Programming Tutorial #4 - IF/ELIF/ELSE
Tech With Tim
Python Programming Tutorial #5 - Chained Conditionals and Nested Statements
Tech With Tim
Python Programming Tutorial #6 - For Loops
Tech With Tim
Python Programming Tutorial #7 - While Loops
Tech With Tim
Python Programming Tutorial #8 - Lists and Tuples
Tech With Tim
Python Programming Tutorial #9 - Iteration by Item (For Loops Continued...)
Tech With Tim
Python Programming Tutorial #10 - String Methods
Tech With Tim
How to Overclock a NVIDIA GPU
Tech With Tim
Python Programming Tutorial #11 - Slice Operator
Tech With Tim
Python Programming Tutorial #12 - Functions
Tech With Tim
Python Programming Tutorial #13 - How to Read a Text File
Tech With Tim
Python Programming Tutorial #14 - Writing to a Text File
Tech With Tim
Python Programming Tutorial #15 - Using .count() and .find()
Tech With Tim
Python Programming Tutorial #16 - Introduction to Modular Programming
Tech With Tim
Python Programming Tutorial #17 - Optional Parameters
Tech With Tim
Python Programming Tutorial #18 - Try and Except (Python Error Handling)
Tech With Tim
Python Programming Tutorial #19 - Global vs Local Variables
Tech With Tim
Python Programming Tutorial #20 - Classes and Objects
Tech With Tim
Cool VBS Script to Prank Your Friends!
Tech With Tim
How to Overclock an AMD GPU
Tech With Tim
Best GPU'S For Mining Ethereum (2018)
Tech With Tim
Recursion and Memoization Tutorial Python
Tech With Tim
Ethereum Mining Rig - Hardware Guide
Tech With Tim
Pygame Tutorial #1 - Basic Movement and Key Presses
Tech With Tim
How to Install Pygame (Windows 8/10)
Tech With Tim
How to Trade Your Cryptocurrency (Bitcoin, Ethereum etc.) For Cash!
Tech With Tim
How to Mine Ethereum 2018 - WORKING (Super-Easy)
Tech With Tim
Microphone Comparison - $10 Mic vs $150 Mic (Blue Yeti USB)
Tech With Tim
Pygame Tutorial #2 - Jumping and Boundaries
Tech With Tim
Pygame Tutorial #3 - Character Animation & Sprites
Tech With Tim
Pygame Tutorial #4 - Optimization & OOP
Tech With Tim
OBS Studio Tutorial - Best OBS Settings
Tech With Tim
Linear Search Algorithm - Python Example and Code
Tech With Tim
Make Any Mic Sound AMAZING! (WITH OBS)
Tech With Tim
Binary Search Algorithm - Python Example & Code
Tech With Tim
Pygame Tutorial #5 - Projectiles
Tech With Tim
Pygame Game - Mini Golf
Tech With Tim
Pygame Tutorial - Projectile Motion (Part 1)
Tech With Tim
Pygame Tutorial - Projectile Motion (Part 2)
Tech With Tim
Pygame Tutorial #6 - Enemies
Tech With Tim
Pygame Tutorial #7 - Collision and Hit Boxes
Tech With Tim
Pygame Tutorial #8 - Scoring and Health Bars
Tech With Tim
Cloud Mining vs. Hardware Mining - 2018
Tech With Tim
How to Install Pygame on Mac OSX (Fast-Simple)
Tech With Tim
Pygame Tutorial #9 - Sound Effects, Music & More Collision
Tech With Tim
Pygame Tutorial #10 - Finishing Touches & Next Steps
Tech With Tim
How to Fade Your Screen in Pygame [CODE IN DESCRIPTION]
Tech With Tim
How to Create a Button in Pygame [CODE IN DESCRIPTION]
Tech With Tim
Pygame Side-Scroller Tutorial #1 - Scrolling Background/Character Movement
Tech With Tim
Pygame Side-Scroller Tutorial #2 - Random Object Generation
Tech With Tim
Pygame Side-Scroller Tutorial #3 - Collision
Tech With Tim
Pygame Side-Scroller Tutorial #4 - Scoring and End Screen
Tech With Tim
How to Create A Message Box in Python - Tkinter
Tech With Tim
Is Ethereum Mining Still Profitable - Is It Worth It (April 2018)
Tech With Tim
How to Run MAC OSX on a WINDOWS PC (Clover Boot-loader)
Tech With Tim
Programming Problem #1 - Alphabet Soup (Beginner/Novice)
Tech With Tim
More on: Prompt Craft
View skill →Related Reads
📰
📰
📰
📰
Three Token-2022 Mints in One Week: Fees, Yield, and Soulbound
Dev.to · atharv shukla
Maximize Google Workspace AI Power: Safeguard Data and Boost Performance in 2026
Dev.to AI
What is Gemini Spark, and what can it actually do for you?
TechCabal
How I use python to save hours every week
Dev.to AI
🎓
Tutor Explanation
DeepCamp AI