This is the slide presenting about how to use Python programming language to create an desktop application at a very basic level.
Target: Non-IT background people who interested in programming.
3. About me
● My name: Nguyễn Đăng Bảo Long
● Current study: University of Engineering
and Technology - VNU
● Main subject: Cloud Computing,
Networking, Information Technology
● Email: baolong.a1yh@gmail.com
4. Get to know each other
● What do you do?
● How many of you have heard about
programming?
● Have done some programming?
Please share it
5. This course rule
1. Use the Google search as much as possible
2. Please ask me as much as possible (feel free to interrupt me if needed)
3. Repeat what I do as much as you can
4. You are allowed to use mobile phone, but use it wisely
7. Course objective
After this course, you will be able to:
● Write your own applications
● Create a simple game from scratch
● Go on studying deeper in Python
8. Desktop app vs. Mobile app
There were about 30
million lines of code in the
Mac version of Microsoft
Office (the whole suite) in
2006.
9. Let’s see how many kind of desktop app do you know
You will have 2 minutes to write down all kind of
desktop app you know.
Let’s see who get the most number.
11. Phase 1: Idea
● An idea is given by a customer or a
leader of a team
● There will be a draft where the app’s
UI is sketched, the app’s functions is
noted
12. Phase 2: Analysis & Design
● After all the requirements have been
clarified, the devs are gonna choose
which technology will be used.
● Then the dev team will focus on
designing the:
○ UI
○ Components in the App (Login part, Paying
part,...)
○ Back-end server, system
○ ...
13. Phase 3: Develop & Test
● At this phase, the dev team is actually
do the coding, building the app part by
part.
● Each part can be accomplished by a
small team.
● There are some peoples, called
“testers”, coming in to find any error in
the app.
● The dev team then try to fix those
errors, or “debug”
14. Phase 4: Deploy
● Bring up the app to the marketplace,
where the user can use it
● At this stage, app will need to be
advertised by the marketing team, in
order to make it popular
15. Phase 5: Maintenance & Update
● After releasing, app shouldn’t be neglected.
● The team should continuously update it,
improve it, keep making new functions.
16. What are we going to do in this course?
● We involve in the developing part
● Assume that all the ideas, requirements is exists, we just jump right in
building it.
20. Why are we using it?
● Easy to learn
● Convenient to use
● Short to write code
● But:
○ Be careful with its syntax, 1 whitespace character
can makes the difference
24. In this part:
1. Install the prerequisites
2. Basic structure of a program
3. The output
○ To screen/file
4. The input
○ Variable
○ Data type
○ Operator
5. Execute part of a program
○ Logic
○ Loop
○ List
○ Function and Module
26. About Python
● Python is an interpreter
○ It’s a program which converts each of your line code, one by one, to a language which the
computers can understand and execute it
27. Python version
There are 2 version:
● Python 2
● Python 3 (currently 3.8.1)
We will use Python 3, since it’s the latest
update
28. Python download and install (Windows)
● Go to the page https://www.python.org/downloads/windows/ and download
the latest version of Python 3
● Install it
● Set the environment variable for python (it already done by default)
● Check with cmd by typing python
29. Python download and install (Linux/Ubuntu)
● Open the Terminal
● Run the following command:
○ sudo apt install python3
○ sudo apt install python3-pip
● Check with command python3
30. Python download and install (Mac OSX)
● Python 2 is installed on Mac by default, but we recommend using Python 3
● Go to the page https://www.python.org/downloads/ and download the latest
version of Python 3
● Install it
● Set the environment variable for python (it already done by default)
● Check with terminal by typing python3
35. Example
Let’s have a simple example, at the coffee
shop
● There are many choices on the menu for
which the customer can orders.
● Each time, the customers will select 1 or
more options for them and their friends.
● The program is to takes the orders,
calculates the price, and prints out the
bill.
36. Example analysis
Input Execute Output
Data about coffee: The menu, the
price for each type of drink.
Customer data: Which drinks do
the customers order.
Maps each drink to its price.
Sums up all the prices.
Displays on the screen for the
customers.
Prints out the bill.
37. So, how are we going to implement all of the above?
39. The “print” Command
● Display something on your screen
Type these lines in your IDE
print(“Hello World”)
print(“””
You can prints out every thing here
It will output with the exact format
“””)
40. How about writing to a file?
You can use the “with open” statement, like this:
with open(“aFile.txt”, “w”) as file:
file.write(“Some random words in here”)
41. Oops, be careful with this indent
with open(“aFile.txt”, “w”) as file:
file.write(“Some random words in here”)
This indent must be exactly 4 whitespace characters.
42. Let’s do a quick exercise
Your job is to draw a mighty sword with any
characters in a .doc file
45. Input from keyboard
You can prompt user with the input command, like below:
input(“Prompting: “)
input(“>>> “)
46. But, where do the inputs go?
● Do they just disappear???
○ Yes and No
● We need to store them somewhere for future use, and that “somewhere” is
called variables.
47. Variables
Variables are like a closet. You can store any
thing you want inside it, and take them out at
any time you want
48. How to use it?
The syntax to define a variable is
variable_name = <something you want to store>
For example:
name = input(“Input your name here: “)
print(name)
49. Other ways using variables
● With number: (You can do the calculating with these variables)
age = 16
sum = 2 + 3 ( = 5 )
product = 5 * 6 ( = 30)
quotient = 21 / 4 ( = 5.25)
● With boolean value:
is_a_girl = True
is_from_Japan = False
50. Be careful using it !!!
● It just works one way
○ This is good: number = 5
○ This is bad: 5 = number
○ This is also bad: number1 = number2 = 5
● Be careful naming the variables:
○ You can use lowercase, uppercase, number, underscore: downUp, UpDown, down_up,
up1_down2
○ Don’t put number at the beginning: 1_variable
○ Don’t use special character: not_this!,
or_this?,...
○ Don’t use word that is used in Python syntax: if, else, for,...
52. Compare 2 variables
● What if we want to know if 2 variables has the same value?
● We use 2 operator: == and !=
○ compare = bigger_number == smaller_number ( ? )
○ compare = bigger_number != smaller_number ( ? )
53. Variable data type
● What will happen if we compare 2 variable that has different data type? (E.g:
a number and a character string)
○ number = 10
○ word = “5”
○ compare = number > word
○ print(compare) ( ? )
● We should convert them to the same data type and then do some operation
on them
○ number2 = int(word)
○ compare = number > number2
○ print(compare)
54. Data Type Conversion
● Four data type you should remember for now:
int, float, str, bool
● Python syntax to switch between them:
converted_value = <convert_data_type>(initial_value)
● Example:
a_number = 3
a_string = str(a_number)
print(a_string)
● Python syntax to check the variable type:
type(variable)
55. An exercise to remember what we have learn so far
● A program that ask for the user’s name and Year of Birth
● Prints out a greeting with information like the following:
Tips: There is something missing in the “print” command, Google search for it!
58. Go back to the earlier example: The coffee shop
How did the computer work after it has received the order?
● Remember the order
● For each drink in the customer’s order:
○ Look for it in the data (menu)
○ Add the associate price to the total cost in the bill
● Show the total price to the customer and
the cashier
59. We divide that process into smaller pieces
Input
Assign the
order to
variables
Get the name
of the drink
Get the name
of the drink in
the menu
If 2 names
are the same
Add the price
to the total
cost
Show the
cost
For each variable
For each drink in the menu
True
How to solve this piece of problem
60. How to solve this piece of problem
● Remember how to compare 2 variables?
● How to direct the program in each case?
Same and not same?
If 2 names are
the same
62. If … else....
Python syntax:
if <conditional expression>:
#Do something if the expression is
true
else:
#Do something if the expression is
false
Also, this is call a comment
Comment line start with the # character
Computers will ignore every comment line
In
Condition
Command
block 1
Command
block 2
Out
False
True
63. Example
Write a program that ask for the user’s age, then tell them that they are:
● Young: if age < 20
● Old: if age > 20
Next level: we use something call elif
● Baby: if age < 5
● Young: if 5 < age < 18
● Grow up: if 18 < age < 60
● Old: if age > 60
64. Back to our previous example
Espresso
$5
Macchiato
$7
Latte
$8
Cappuccino
$10
1 latte please!
65. Practice makes perfect...
Create a program that:
● Require user’s input for weight and height
● Calculate the body mass index (BMI)
● Prints out the result to the screen (and may be some advice :p)
66. Another problem
● How to print out 1000 lines, each
line has a word “Hello” in it?
● How about 1000*1000 lines?
print(“Hello”)
print(“Hello”)
print(“Hello”)
print(“Hello”)
print(“Hello”)
print(“Hello”)
print(“Hello”)
print(“Hello”)
print(“Hello”)
.
.
.
.
.
.
.
.
.
.
print(“Hello”)
print(“””
Hello
Hello
Hello
Hello
Hello
Hello
Hello
Hello
.
.
.
.
.
.
.
.
.
.
Hello”””)
68. While
● To solve that problem, we use loop syntax
● In Python, we have 2 syntax for this:
while command
○ while <conditional expression>:
# Do some loop command here
In
Condition
Command
block
Out
False
True
69. For… in...
● To solve that problem, we use loop syntax
● In Python, we have 2 syntax for this:
for command
○ for i in range(0, <number of iterations>):
# Do some loop command here
● range(start, stop, step)
● Why do we need to start from 0?
In
i < num
Command
block
Out
False
True
70. Example
A program that prints out a table that:
● Compare between 2 types of temperature
measurement units: Celsius and Fahrenheit
● Start from 0 degree C to 100 degree C
● Each line is 10 degrees difference
● Use the following formula
71. Loop benefits
● Repeatedly does the same job, so you don’t have to write the same code for
many lines
● Makes the source code of your program more readable
72. Keep practicing
Build a program that:
● User inputs 1 number n (1<n<1000)
● If n is out of the above range, prints out
the error
● Else, prints out the sum of all the number
from 1 to n
● Please don’t use this formula, use loop
statements instead
73. Comeback to our previous example
Input
Assign the
order to
variables
Get the name
of the drink
Get the name
of the drink in
the menu
If 2 names
are the same
Add the price
to the total
cost
Show the
cost
For each variable
For each drink in the menu
True
74. How to store a huge number of value wisely?
● How about this piece of problem?
● What if the customer order 10 or 20 different
drinks?
○ Store them in 20 variables is not a good idea
○ Naming each variable will become nightmare if the number
of them increase
● Is there any another way to store this big number
of value?
Assign the
order to
variables
75. List
Use to store values in an effective, organized way
John
25
john@example.com
Name
Age
Email
John 25
john@example.com
John’s information
22/2/1995
DOB
22/2/1995
76. How to use List
● Define a List:
john_info = [“John”, 25, “22/2/1995”, “john@example.com”]
● How to use an element in the list:
Try this:
print(john_info[2])
77. How index works in a List?
john_info = [“John”, 25, “22/2/1995”, “john@example.com”]
0 1 2 3
78. Actually, the “for” loop and “list” make the perfect match
● You can use for statement to get the values out of a list
● For each value in the list, we do something with it
john_info = [“John”, 25, “22/2/1995”,
“john@example.com”]
for info in john_info:
print(info)
79. Let’s check back the previous example
● Seems like we have everything we need to do all of this
● Let me show you how to implement all of this at one
Input
Assign the
order to
variables
Get the
name of the
drink
Get the
name of the
drink in the
menu
If 2 names
are the same
Add the price
to the total
cost
Show the
cost
For each variable
For each drink in the menu
True
80. The last skill: Function and module
● Why do we need this?
○ Functions are like the blueprint of codes
○ You can reuse it as many time as you want without retyping
the code
○ Make the program’s code more readable
● Syntax:
def function_name(input_to_function):
# Do something here
● Modules are like the collection of functions, you
can share with others developer or keep it for later
use
81. Prepare for next week
● Using pip3 to download and install pyqt5 tools
82. The work you can do at home
● At the end of each session, you will be given 1 problem which you can do at
home.
● The result of your work will be assessed based on a variety of criteria.
● Each criteria passed, you will score some points.
● Candidates who get highest scores will have some gifts.
Join this Google classroom: hydfs5h
83. Books you can read at home
● Learn Python The Hard Way - Zed Shaw
(recommended!)
● Python rất là cơ bản - Võ Duy Tuấn
● Core Python Applications Programming -
Wesley J Chun
Editor's Notes
I’m not very good in English so might talk Vietnamese sometimes
How many of you have heard about programming
Have been programming
2. Hãy hỏi nhiều vì có thể tiếng Anh ko rõ thì sẽ nói tiếng Việt hoặc mình có thể coi mặc định là đã đúng nên khó cho người mới
https://www.visualcapitalist.com/millions-lines-of-code/
Nghĩ xem làm như nào họ tạo được những app đó? Các bước
There are many way to understand this process but in conclusion, it mainly contains the following
https://lvivity.com/5-phases-mobile-app-development-lifecycle
Easy to learn:
Even 10 year-old kid can acquire it
There are hundred, may be thousand of document about it out there, on the internet
Convenient to use:
NASA scientis use it to launch rocket
There are various tools which can help us develop our apps, tools here mean library, framework...
Short to write code:
We can compare the same purpose app with other programming, if C/C++ will need 30 line to work, Python only need about 5 or 6