Sunday, January 15, 2017

Python Input from User

Howdy!

Before going on, I assume:

1. You've installed PyCharm
If you haven't, please see this first.
Installing Python IDE:
https://umpythonworkshop.blogspot.my/2017/01/installing-python-ide.html

2. You know how to open up a new file in PyCharm.
If you don't know, please see this first.
Python Basics:
https://umpythonworkshop.blogspot.my/2017/01/python-basics.html



If you fulfill the above assumptions, continue!


***

WHAT WILL WE DO IN THIS POST?
- Learn Python input and output.


Suppose we wanted an app to greet user.
We want the user to type his/her name,
then say hello to him/her.

just type these two lines in PyCharm Editing Box.

user_name = input("What is your name?")
print("Hello there,", user_name)

WHAT DOES THESE 2 LINES MEAN?

First, i ask the computer to ask user for input,
and i store the input in user_name



THE FIRST LINE:
user_name here is called a variable.

A variable is like a box.

A box can store anything.
A box can store a kitten, a dog, a number, your age, some words, your name, a whole paragraph, ...
In our case, user_name is used to store user's name - which is a few words.


(A box can store kittens, numbers, decimals, words, paragraphs)

input() is a method to ask the user's name.
Between the parenthesis (), you can have some words to ask the user.
In this case, it's "What is your name?"



THE SECOND LINE:
We've discuss the method print() in our previous post.
Previous post (Python basics) : https://umpythonworkshop.blogspot.my/2017/01/python-basics.html



If you've noticed, there is quotes ("") in "Hello there," ;
But no quotes ("") in user_name.

Because "Hello there," is a string ;
And user_name is a variable name.


IMPORTANT: What is a string?
A string is a data type any character or words or sentence or paragraphs enclosed in quotes ("").
You'll learn more about data type in


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

And in PyCharm Run Box, you'll see this.




Try to type in your name, and hit  ENTER 




VOILA!

A talking app!

Try to change a few things on your own.

user_name = input("What is your name?")
print("Hello there,", user_name)

You can change the above lines to

age = input("How old are you?")
print("You are", age, "years old.")

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




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:

Installing Python IDE

Heyy sup! :D :D :D

In this post, we'll talk about installing Python IDE.

What is a Python IDE?
- In short, it's a software to run Python.
- It helps you to identify errors in your code.
- Before you learn Python, just download it.

There are a lot of Python IDE out there,
but the best Python IDE i've used for years is
PyCharm
Above is the logo of PyCharm!


****


Before installing, please note:
There are TWO version of PyCharm.

1. PyCharm Professional
> More features
> $199 per year, but FREE for Students

2. PyCharm Community
> Less features
> FREE for everyone


If you're a student,
you'll have a student email from your university or college.
Use the student email, and download PyCharm Professional!
It's FREE for students!


***


Alright, You're ready to download PyCharm now. :D
Windows: https://www.jetbrains.com/pycharm/download/#section=windows
Mac: https://www.jetbrains.com/pycharm/download/#
Linux: https://www.jetbrains.com/pycharm/download/#section=linux



***


You've downloaded PyCharm?
It's time to get started!
Learn the basics of Python here: :D :D
Python Basics: https://umpythonworkshop.blogspot.my/2017/01/python-basics.html