Something old, something new. Let’s learn Python, out of the blue.
One of the goals I’ve had for myself, is to start delving more into Linux (Ubuntu), and also learning to code in Python.
I decided to do this for a few reasons, personal growth, future career development and additional knowledge to name some. In order to do this, I realised I needed to learn Python, even if it was one step at a time.
Python is still one of the best languages to learn in terms of desired languages, so if I wanted to move into a job sector which was more remote (like Software / Games Development), I could already develop some basic skillsets. I also find Python very interesting, because if something doesn’t work, or you can’t find something to do what you need. You can simply write your own module, and then share it as part of your portfolio on Github, for others to use.
The reason I chose to learn my own way, is simply because it’s the learning method I work with. I am a Kinesthetic learning, which means I learn by doing it myself, making mistakes, figuring out how to fix those mistakes. It’s a hands on learning approch. I tend to learn better through repetition.
I’m not a person who can learn to code un Python by simply watching something like a Youtube video. All this teaches me is either how to remember to do code for the project I was given. Or worst case, I completely forget what I was doing because I’m not really paying attention when typing, I’m just mimicking what it tells me to do.
Learning methods this way need to force user interaction. By doing it helps them remember. By having my own little Project, it helps me learn. This is because I get minimal exposure into how I do something and it forces me into working out how to fix it by reading up on the errors.
My first Python project
One of the first things you need to do with Python, is to create your own Project. This starts with an idea, normally the easiest ones are those which asks questions, as it’s normally just a few lines of code. It doesn’t matter how simple it is, even if it’s something that looks up the date and time in Python, then outputs it onto the screen.
It’s a start, and gives you something to learn.
My first project in Python, was based around the following:
The person would type in a number, the computer would apply some mathematics, and then a random number. The person would then have to keep inputting a number “guessing” until the right one was found
What problems did I encounter?
The main problems I encountered with my own Python game project, is that I had no knowledge on what I was doing. In order to learn, I broke it down in my own way. This is similar to the method I did below
- Do I know what I want it to do? (e.g a Guessing game)
- Now that I know what I want it to do, what’s the first step (e.g – Computer asks a question)
- OK, now I know the first step, how do I get the computer to do this (e.g What code do I use)
- Damn, I don’t know the code (e.g How do I find it? – GOOGLE!)
- As I note here, it took me 1 week to finish this doing 2 or 3 hours here and there. A total of 150 Google searches, and a lot of headache. Overall maybe 25 hours to write this basic project with no knowledge.
After each successful step, and constantly throughout, I was testing my code in the Ubuntu terminal. It’s easy to understand why Python or coding can annoy programmers and developers. A missing comma, a misplaced capital, an intent too far, and the code goes awry. From my experience, I found that by constantly testing, I could fix the little problems before they became big.
I only moved on with the next section of my code, once the previous section was working. I also added comments along the way; denoted by using a hash prior to the code # so that I could tidy it up, and then also skip sections of the code, and only focus on what I wanted to work on at the time.
The hardest challenge for me, I think was caused by the while loop. I was trying to apply mathematical formulas to the questions which were input as numbers. The problem is when you ask questions, the computer interprets it as a “String” (in other words text). It kept breaking my loop question (where you have to keep guessing), because the computer wasn’t recognising it was a number.
This is because to identify it as a number, you have to tell the computer it’s a number (designated as an INTEGER)
After I overcome this hurdle it worked as intended.
Did my game work?
Yes, you can find my 1st Github project using this link “Guess the number”
It’s probably very buggy, and can easily break, but for my first Python project, it did what I expected of it. That was for me to learn Python basics, whilst understanding the structure of the program, and troubleshooting errors. As my knowledge gets better in Python I can start writing more.
I’ve left the code I used with a couple of my comments in the project, so that if you want to learn the method I used
Need to learn Python yourself?
Try free methods first (Youtube, Google Searches, Udemy, Amazon Kindle). As I’m always going to suggest a free method when possible. If you’re one of those people who think they learn by books, here are the top rated books on Amazon. They’re all high ranking ones, so I suspect they’re the more recommended ones to use.
Full disclosure – these are all affiliate links. If you decide to use them, and make a purchase. I will earn a commission, at no extra cost to you. I picked the highest ranking ones that matched for beginners in the programming section.
- Python Crash Course 2nd Edition by Eric Matthes
- Learn Python in one day by Jamie Chan
- Hands on Python Beginner by Musa Arda
- Python Programming for beginners by Andrew Park
- Python in Easy steps by Mike McGrath