Learning to code the right way


Home | Blogs

Are you starting to learn to code, or do you not know how to code but want to? Coding can be very hard, especially when starting out and when everything is new.

The way I learned to code was from my dad; he taught me a little, but then I started doing my own thing. I think that the best way to learn to code is by doing.

In all of my examples, I will be using the language Python because it is the easiest to explain and does not take up much space to write. I would recommend that, once you can do some things in Python, you explore and try other languages.

To set up Python, you can install it here. I would also recommend vscode as your code editor. Once you have both installed, make a folder and open it in vscode.

Some of the basics you need to know are what a variable is and what a function is.

A variable is a place where you can do something and save the output to use later. Think about it like a cake, you can bake a cake but once you are done you can save it, later you can bring it to a party. At this party, your cake is not fully finished, so you can bring it back and bring it to a new party (which I would not recommend, but you get the idea).

A function is some code that you would like to use multiple times. Imagine you are playing a game. Do you want to always run across the whole map to get somewhere, or would you much rather run there once, then teleport back there without doing all the hard work again?

Now think of a programming project you want to code; for this example, ask the user for their name and then say hello to them.

Now let's think about what the first thing you need to do is—we want to ask the user a question. Let's go to our handy dandy search engine and search python (or whatever language) how to ask the user a question, Google brings you to a nice website where it tells us exactly what to do. It says

name = input("What is your name?")

This is the first part of our program, but what is that name = at the start? Let's look farther down the code and look for a time where it says something about name. The next time we see names, it's on this line.

print("Hello " + name + "!")

I think you can start to see what is happening. To make sure, let's put this in our Python file and run it (there should be a run button at the top right of your screen). We now see this:

What is your name?

It shows a cursor blinking, so let's put something in. We know it should ask for some input, so let's type Arthur, press Enter, and see what happens.

What is your name?Arthur
Hello Arthur!

Now we see this output, and I think on the first line, having "name?" touch our name is kind of weird. Let's read our code for when we get the input. We see that it says input("what is your name?") and we want a space, so let's change it to input("what is your name? "). We run the code now and see that there is now a space for our input!

Let's change our code a little and make it do the function x + 5, so let's make it so we ask the user for a number and we will add 5 to it.

number = input("What is your number? ")
print(number + 5);

When we run this, we get an error. It says we can't contain a str and an int, but we have an int, not a str. Searching for python number user input, our first result says

x = int(input("Enter a number: "))

This looks close to what we had, but let's look at what the big difference is: the int around the input. Let's try adding that to our code.

number = int(input("What is your number? "))
print(number + 5);

We run it, and it works!

You might think that we have not actually learned that much, but we have learned the most important aspect of coding: searching the internet for a solution. We can search for how to make a GUI window, how to make a game, or even how to make a calculator. The most important part of programming is being able to approach a problem in small steps and tinker. That is what we did—we found what we wanted online and tinkered with it.

The most important part is to remember what you learned. If you need to know how to get user input in the future, you should remember about input(), You need to remember how to get a number input int(input()). If you can remember all of these things, then you will be a master programmer in no time.