Welcome to this python tutorial
Please open another browser so that you can do some coding along with me. Some of it will be copy and paste but as long as you follow it should be okay. We will be using a language called Python. It has been around for several years and is currently very popular. Languages can be fashionable. There are many others including C, C++ and Java and PHP. Once you understand the basics of one language then it is easy to change to another as concepts are similar but the syntax changes a bit.
links
function (a, b) {
sum = a + b;
return sum;
}
Setting up
I am not going to get you to install python. I wanted to dive in straight away and open way to do this is to use a browser with python already set up. There are various ones available which I will list below.
Hello World
For about 40 years all computer programming tutorials begin with the language printing the sentence "Hello World". So let us do that.
# This is my first code
Print(Hello World.")
So we see here that the term we put in inverted commas in a bracket is printed out below. If I forget the inverted commas, it doesn't work and says there is an error. So fix it again and make sure it runs
Sometimes I like to repeat myself and print things out 5 times as below
Is there an easier way to do thinks repeatedly ? Well there are several. Here we are using a for loop. We use the term for i in range(0, 5) which wants us to do something 5 times. With each cycle I increments. The most important factor is the indented code after which means that each time the loop runs it prints "Hello World". Note that "Hello world" must be indented.
If you do not indent it then it is not happy. The colon: is a sign to indent the line below.
See below. Note that the count never gets to the final number, it starts at 0 but never gets to 5. Range (0,5) is 0,1,2,3,4 and there are 5 numbers printed out.
We can do something even neater - we can use this to print out all the numbers to 5 and we can use a comma and then a word after in inverted commas.
We can even do some maths and print the square of each number.
We can even do some maths and print the square and cube and quadruple of each number.