Yo Steemrs, I'm Pooria.
As I explained in my intro yesterday I'm starting a coding class here. Get ready for some awesomeness and enjoy the ride.
How ?
Coding is easy, much easier than what you think. Though starting it and doing it professionally is hard.
In this series of short tutorials I'm trying to teach coding step by step to beginners. The goal is not to get into unnecessary theoretical explanations and jump into writing codes that show us some results early on. This approach is perfect for people who learn by doing (like me) and are confused by the amount of explanation written by other learning resources. Enough of talking, let's start!
Language
I use Python 3.0 to teach coding in these tutorials. The reason I choose this language is selfish because I want to review it myself and writing these articles gives me the opportunity to do so! However, It's one of the best languages to start coding with. It's simple to learn, the skill set is easily transferable to other languages and it's very much popular. Services like Instagram are created with Python, you can build websites with it, get lots of freelance gigs and it's the pathway for getting into making hardwares (Raspberry Pie, Arduino) as well!
How to run codes?
Don't worry you don't need to setup anything or have any special operating system. In this tutorials we use Repl to run our codes. You just need to open the link, no signup required and start coding! That's it.
Tip: you write the code in the left side of screen. Hit the run
button on top and see the results on the right side
Let's Code
Coding is basically giving instructions to computer to do things for us. For those instructions to be meaningful we need to store values (like numbers) in the memory to do some calculation on them. We call those values variables
. In order to works with variables we should give names to them like this:
x = 1
We can change them and do basic calculations with them:
x = 1
x = x + 1
x = x - 1
x = x * 2
x = x / 2
** Note: *
is multiply and /
is division **
Amazing! now we have a place in memory of our computer that we stored number 1
inside it. Whenever we want to use that number we call it by it's name which is x
. Makes sense huh?
There are different types of variables. But for now let's only work with two popular ones. Strings (texts) and Integers (numbers). For strings you should put them inside "
or '
but for numbers there is no need for that.
A string:
my_name = "Pooria"
An Integer:
my_age = 26
As you can see this time I used more meaningful names for my variables. Remember to don't start a variable name with a number and don't use spaces in it.
We can also show messages on the screen:
print("Hello Steemers!")
Run the code above in your editor (Repl) and see the result in the right side.
Working with variables
Amazing. Now we know about variables and learned how to show output to our users. Let's learn how to output variables:
my_name = "Pooria"
print("Hello ", my_name)
As you can see I used a ,
to chain (as we say concatenate) Hello
to the variable of my name.
Try the code and see the result.
More variations:
my_name = "Pooria"
my_age = 26
print("Hey " , my_name, " How is it going buddy?")
print(my_age, " years old isn't that bad")
Don't copy/paste, type it inside the editor from scratch. If you copy you will forget it simply two days later!
Getting input from user
It's also damned simple. We want our user to give us his/her name.
name = input("Please enter your name")
That's it. This statement will wait for user to type his/her name and put it inside a variable called name
.
Try it yourself
Now your turn. Open this link and write a program to:
Get the name of user and her age. Say hello to the name and print she looks 3 years younger than how old she actually is
Example:
Please enter your name: Pooria
Please enter your age: 26
Hi Pooria, you look 23
Ask your questions and write the code in comments if you want a review from me and please follow my account to get the other tutorials as I write them.
Cheers,
Pooria
Image Source: https://www.instagram.com/ghanipradita/