You can access the full course here: Bite-Sized Python
Hello, everyone. Before we begin writing any code, it’s a good idea to make sure we have the latest versions of Python and Pygame as well. So in this section, we’re going to download and install both Python and Pygame for Mac, specifically.
So, we’re gonna go ahead and open up a new browser, and we’re going to start by downloading Python. So simply search for download python. We’re gonna click this first link, which is just python/downloads, and we’re gonna download version 3.6.5, and it will download a package type file. Okay, and we’re just gonna follow these instructions here, starting with the intro.
All right, so now that this is finished, this window probably will have popped up, which gives you all of the main pieces of software that are installed with Python 3.6. Obviously, there’s a lot of other stuff as well, but just make sure that IDLE is here, as this is going to be the IDE that we’ll be using. So, you can close it up if you want.
And now that we’re done, we can download and install Pygame. Now, since we’re using Python 3.6, the actual download that we want isn’t found on the Pygame site. So if I search for Pygame download and go to Pygame’s main download site, I actually don’t see the version I want. We’ll actually have to do a little bit of work in the Terminal.
So, what I want you to do is go ahead and open up a new instance of the Terminal. If you press Command and Space, this will bring up your search window, and we’re just going to search for Terminal, and it will start a new window here. So, what you’ll want to do is go for python3. As we’re using Python 3, we wanna make sure that this is gonna be the version that we’ll use. We’re going to go dash m, or hyphen m, and then we’re going to type pip install Pygame, capital P, double equals here, 1.9.3. So, this is what it will look like in the end. So, python3 -m pip install Pygame==1.9.3. Note the double equals.
So once we go ahead and click Enter, what this will do is it will install the latest version of Pygame into our Python 3 folder. And it should be saved under Macintosh HD. We’ll want to go into Library, into Frameworks, we want to go to Python Framework, Versions, 3.6, we want to go into library, all the way down to python3.6. We scroll down to site-packages and then search for Pygame. There should be Pygame right around here. So there should be a Pygame folder. There should be Pygame-1.9.3.dist-info.
So, that is how you get your hands on the latest versions of Python. Now, the next lesson in this series is, I think, pretty much the same thing for Windows. If you are using a Mac, then this went smoothly. You can skip ahead to the next section which we’ll start to explore the IDLE environment. Once that’s done, we’ll move on to Python basics. That is pretty much all the setup that we need for this.
Hello, everyone, and welcome to our tutorial on how to install Python and Pygame for Windows 10.
And we’re simply going to Google search for download Python. Okay, this should take us to the Python site, if we follow this first link, Python.org/downloads, and the version we want is 3.6.5. And this is just going to begin to download an executable file, so what we want to do is add this to our path, and then we’re going to select this guide up here.
Now this should download everything we need (IDLE, Pip, and the documentation), and is gonna create the shortcuts of file association. So we’re just gonna go ahead and click on this, alright, so it looks like this setup was successful. We have it successfully downloaded and installed it, it’s just a matter of accessing it.
So for this we’re actually going to, just go to our search, and we’re going to look for Python. We’re Python 3.6, but we’re not going to open this up, cause this will actually open up a Terminal or Command Prompt. We’re going to right-click here, we’re going to open up the file location, and it should take us to this folder, or this directory where we have a few items.
We have IDLE: this is actually going to be the program that we’re going to write our code in; if you want to take a look at what that looks like, go ahead and open up, although we’ll explore it more in the next section anyway. There is python 3.6.- this is just a way to build or run up a Command Prompt to Terminal. There’s manuals and manual documents.
So what we’ll want to do is actually right-click on this again, and we’re going to go for open file location, and this should take us to a new file or new directory. So within here, we should have scripts, so we’re going to our scripts folder, right-click on that, or double click on that, and you should see a bunch of easy installs. And there’s the pip, so the Python packaging, I think it’s something to do with Python packaging installer or something, and so we’re not actually going to run these just yet. But, you’re going to copy this file path. So if you right click on here, we’re just going to select this all, and we’re going to copy it (so Command C)- this is just copying it.
So next step is gonna involve a little bit of Terminal work. We’re actually going to open up a Command Prompt into CMD- Terminal or either of them will open up the same thing- so we’re just going to go ahead and open that up now. So you see it says C, colon slash users, slash user. We’re actually going to right click here, and it should just paste that in as soon as we right-click. If not, then just paste it in. I had forgotten that you changed directory command, so we’re just going to go CD, and then space and this. So CD is the command for changing the current working directory, so change directory, and so we’re just going to change the directory to this path. So let’s click Enter, and now we’re in this path here.
So what we’re gonna do is we’re going to select pip- or type rather- pip install pygame, we’re going to click enter, and this will start the installation of Pygame. The great thing is that it will actually already down, it will download the latest version of Pygame. In my case, I’ve actually already downloaded it as you can see, requirement already satisfied. But if you haven’t downloaded this, this will just take a few minutes to actually download it, so it should give you like a progress bar, tell you how far along it’s on, and then once it’s done it, will give you a command like this.
Hello, everyone, and welcome to your first official lesson of this tutorial. Here we’re just going to become a bit more familiar with Idle, which is how we’re going to build and run our Python programs. And we’re gonna build a very, very simple input output-type Python program, just so that you can get used to the flow of things.
So go ahead and open up Idle now- it should have been automatically installed with Python 3.6 if you’re using a Mac. You should be able to find this under Launchpads in your application’s folder; simply select Idle.
So this is what’s called a Python Shell in which we can actually write and execute statements right away. Now this is great for kind of single line statements. For example, if I wanted to just print something out, I could say print and then I could put in these quotes here something like “hello”. If I press enter, it’s just going to compile and run that line right away. Now what this isn’t great at is writing multiple lines of code and then having them execute complex logic. For that, we might need a new text file, and then we just run that text file rather than doing everything in the shell itself.
So I’ll show you how to set the App, and then we’re just going to go into Idle and we’ll select a new file. Now it’s usually a good idea to give your file a name right away. We just got to go to file, we’re getting out to save as, and let’s just give this guy a name. I’m gonna call mine Hello (you’ll see why very soon), and I’m just gonna save it to the desktop. Make sure it’s a Python file with a py extension. Go ahead and click save.
Now if we want to do pretty much the same thing that we did here, what we could do is actually just run that same line of code, such as print something like hello. If I give this a save- make sure I save it and the asterisk will disappear- and then I go to this guy; make sure that this window is selected. We can go to run, run module or just press F5, okay. It will do pretty much the same thing, it restarts it and then it just runs up file there. In this case, the results are exactly the same as with the first case, so that’s great, but how is it different from just running it in the shell? Well in our case it isn’t.
What we can do is make this file at least more complex, and what we’ll do in our case is actually have it take in some input from the user, and then do something with that input and then produce some output. So the way in which we take input in a Python program is through the input function. I’ll show you how to use that in just a second.
Let’s just call our input something like input name, and we’re going to set this equal to the function call to input. We’ll open up the parentheses beside it. And within these parentheses, we’re going to put a quote or a couple of quotation marks here. And then within these quotations, we’re going to enter the prompt for the user. So this will be something like enter a name. Now what we’ll do is we’ll create another variable called output text. And this is just going to be something like there’ll be some quotes, can say hello space, and then plus whatever name that we entered, so input name.
So we’re just gonna go ahead and give the safe in our print statement rather than just printing hello; we’re actually gonna print out our entire output text. So let’s give this one final save, run the module, and you can see here that it’s prompting us to enter a name. So I’m gonna enter my own name, press enter, and now it says “Hello Nimish”.
When we come back, we’re going to start learning about our Python language basic. So hopefully all these different components will make a little more sense, and we’re going to begin with the topic of variables.