Saturday, January 14, 2017

Python Basics

Hey there!
Only continue reading if you have Python IDE installed
Install Python IDE:


Some thoughts.


When we learn programming, the most effective way is to learn by building.

Like Learning piano, get your hands on it.

Let's start.


Kay,
we'll do a program that outputs "Hello World" to the computer screen.
It's just the first thing u do when you learn a programming language.

Kay,
open up PyCharm.

In PyCharm, click
File -> New Project

You'll see this.



Change "untilted" to anything you want. It's just the name of our python folder.


Then, click  Create .

Then, You'll see this.


Click  OK .


Then, create a new Python File by
tapping  ALT  +  INSERT  on your keyboard.



Choose "Python File".


Name it anything you want. It's the Python filename.
Click  OK .


***

Now we're typing in Python.

***

Try to type this line in the file.

print("Hello world")




WHAT DOES THIS LINE EVEN MEAN?

- In Python language, print means show anything in between the parenthesis () to the computer screen.

- so, in this case, print show the word Hello world to the computer screen.


NOTE:

You must type the word "print" in lower case

If you type it in upper case, like this:

PRINT("Hello world")

it will not work.


Why?
Cuz Python only recognize the word "print" in lower case.



Running our First Program.

Let's try to run our
FIRST PROGRAM

by hitting

 ALT + SHIFT + F10 

and hit

 ENTER 


Down there, the there is a screen - which we call it the run screen.
In the run screen, You'll see this.




CONGRATULATIONS!

You wrote the first program in Python.

Imagine how simple is that. Only one line.

To print Hello World in some other languages,
it will take up to a few lines, some are even up to 5 lines!!!

If you experience any problem, please comment under this post. I'll get to you ASAP.

***

NOW change to line to

print("I live in Malaysia")

and run it using  ALT + SHIFT + F10  and hit  ENTER 

and see what happens.

---

THEN,

change it to

print(102)

and run it using  ALT + SHIFT + F10  and hit  ENTER 

and see what happens.


---

NEXT,

change it to

print("I have RM " + 120.35)

and run it using  ALT + SHIFT + F10  and hit  ENTER 

and see what happens.


***


Python can print numbers, words, and even decimals.

If you're printing words or characters,

remember to put it in quotes, like so:

"Words here"

For numbers and decimals,
quotes are not required.


***


Now that we've learned how to OUTPUT stuffs to the computer screen.

It's not very useful.

Since a computer program usually has INPUT, PROCESSING, and OUTPUT.

We'll learn to INPUT stuffs from user next.


Python Input From User:
Link:

No comments:

Post a Comment