COURSE LESSONS:
PYTHON PROGRAMMING
Duration: 60 periods
Lecturer: MSc. Luu Thi Thao
Phone number: 0978131419
Email: luuthao23@[Link]
Slide:
NOTE
DO NOT USE YOUR
NO PRIVATE TALK PHONE FOR NO SLEEPING FULL RECORDING
PERSONAL WORK
On time No phone No sleeping Writting
THAO THI LUU Slide: 2
TABLE OF CONTENTS
DETAILED COURSE CONTENT
Chapter 1: Introduction to Python programming language
Chapter 2: Control structures and functions
Chapter 3: Advanced data types in python
Chapter 4: String - file and exception handling in python
Chapter 5: Object Oriented Programming in Python
Chapter 6: Real Project
LƯU THỊ THẢO Slide: 3
DOCUMENTS
BOOKS AND INTERNET
[1] Fundamentals of Programming Python, Richard L. Halterman. Southern
Adventist University 2019
[2] Tài liệu giảng dạy do Khoa biên soạn bằng Tiếng Việt bổ trợ đi kèm
[3] Nguyễn Ngọc Giang, Phan Xuân Vọng, Nguyễn Quốc Anh, Đường vào
lập trình Python, NXB Đại học Quốc Gia, 2020.
[4] Wes McKinney, Python for Data Analysis, 3rd Edition, O’Reily Media,
Inc, 2022.
LƯU THỊ THẢO Slide: 4
Chapter 1: Introduction to Python
programming language
WHY LEARN PYTHON?
LƯU THỊ THẢO Slide: 6
WHY LEARN PYTHON?
• Python is a programming language used to develop desktop, web,
mobile applications
• Suitable for deploying backend applications, data analysis, AI,
machine learning, big data, data visualization
• Python is used for game development
• Used to build small scripts to automate work
LƯU THỊ THẢO Slide: 7
WHY LEARN PYTHON?
LƯU THỊ THẢO Slide: 8
WHY LEARN PYTHON?
LƯU THỊ THẢO Slide: 9
DOWNLOAD AND INSTALL PYTHON
• Download and install Python from:
[Link]
LƯU THỊ THẢO Slide: 10
LƯU THỊ THẢO Slide: 11
DEVELOPMENT ENVIRONMENT
• Tools Offline: Anaconda, Visual Studio Code, Jupyter, …
• Tools Online: Google Colab
LƯU THỊ THẢO Slide: 12
INSTALL ANACONDA
LƯU THỊ THẢO Slide: 13
JUPYTER
ENVIRONMENTAL TOOLS
Môi trường chạy Tương tác cho thấy
code Python dạng kết quả chạy chương
tương tác trình từng bước
JUPYTER
Giúp ích cho các lập
trình viên mới làm
quen với Python
LƯU THỊ THẢO Slide: 14
JUPYTER BASIC INTERFACE
LƯU THỊ THẢO Slide: 15
JUPYTER BASIC INTERFACE
LƯU THỊ THẢO Slide: 16
USING JUPYTER
• Document Title, default is Untitled
• When clicking on this section, a window will appear to enter the
file name
LƯU THỊ THẢO Slide: 17
CODE, MARK DOWN
• The document content contains cells with code or markdown
content, this is the main working area.
LƯU THỊ THẢO Slide: 18
CELL VÀ MARKDOWN
LƯU THỊ THẢO Slide: 19
CODE
• Code (default when adding a new cell): allows writing code and
executing commands written in a cell. The execution result will be
displayed right below the cell.
LƯU THỊ THẢO Slide: 20
MARKDOWN
• Markdown: allows users to edit, read and decorate text, can insert
images, videos,... is a useful tool for taking notes on lesson
content, annotations
LƯU THỊ THẢO Slide: 21
ENTER DATA FROM THE KEYBOARD
• In python to enter data from the keyboard we use the input()
function
• Syntax:
- input(‘Display string: ‘);
- Variable = input(‘Display string’);
LƯU THỊ THẢO Slide: 22
ENTER DATA FROM THE KEYBOARD
Keyword: input
Basic syntax:
_i = input("Enter input value: ")
Type casting syntax:
_i = float(input("Enter input value: "))
_j = int(input("Enter input value: "))
LƯU THỊ THẢO Slide: 23
FUNCTION TO OUTPUT DATA TO THE SCREEN
• The print() function is used to output data to the screen on
different lines
• Syntax:
– print(‘Character’)
– print(variable)
– print(‘Character’, variable)
LƯU THỊ THẢO Slide: 24
FUNCTION TO OUTPUT DATA TO THE SCREEN
Keyword: print
Basic syntax:
print('Float value:', _i)
print('Integer value: ',_j)
print('Float value:', _i,'; Integer value: ',_j)
LƯU THỊ THẢO Slide: 25
NOTES IN PYTHON
• The larger the program, the more complex it becomes, making it
harder to read the code
• Use comments to make code easier to read
• In Python, comments start after the # character (a line)
LƯU THỊ THẢO Slide: 26
VARIABLE, STRING DECLARATION
• Variables are temporary storage places for data in Python
• Variables have names and follow the same naming rules as in
normal programming languages
• Variables have data types
• In Python, string values are declared in brackets ‘’ or “”
LƯU THỊ THẢO Slide: 27
ARITHMETIC OPERATORS
LƯU THỊ THẢO Slide: 28
ARITHMETIC OPERATORS
Operation Meaning
+ Add two values
- Difference of two values
* Multiplication
/ Division
// Divide by integer
% Divide by remainder
** Power
LƯU THỊ THẢO Slide: 29
ARITHMETIC OPERATORS
LƯU THỊ THẢO Slide: 30
COMPARISON OPERATORS
Operation Meaning
== Compare by
!= Not equal
> Bigger
< Smaller
>= Greater than or equal to
<= Less than or equal to
LƯU THỊ THẢO Slide: 31
COMPARISON OPERATORS
LƯU THỊ THẢO Slide: 32
LOGIC OPERATORS
Operation Meaning
and True only when all conditions are
true
or Returns true if one of the conditions
is true
not Returns the opposite value if True
then returns False and vice versa
LƯU THỊ THẢO Slide: 33
LOGIC OPERATORS
LƯU THỊ THẢO Slide: 34
PRACTICE
[Link]
Exercise 1: Recode the following slides: 22, 24, 30, 32, 34
Exercise 2: Enter two integers from the keyboard. Calculate the sum and
print the sum of the two integers.
Exercise 3: Enter a string of characters from the keyboard, print that
string of characters.
LƯU THỊ THẢO Slide: 35
PRACTICE
Exercise 4: Enter three integers from the keyboard. Calculate and print on the
screen:
a) Sum and product of the three numbers
b) Difference of any 2 of the 3 numbers
c) Division to get the integer part, remainder and exact result of any 2 of the 3
numbers
Exercise 5: Enter three strings of characters from the keyboard. Print on the
screen a string of characters combined from the three input strings. For
example: Enter 'Nguyen', 'Van', 'Minh', the printed result is 'Nguyen Van Minh'.
LƯU THỊ THẢO Slide: 36
PRACTICE
Exercise 6: Calculate and print the circumference and area of a
circle. With the radius value entered from the keyboard. The formula
for calculating the circumference: CV = 2*_R*_pi; DT = _pi*_R*_R
(where: _pi is the number pi = 3.14, _R is the radius of the circle)
LƯU THỊ THẢO Slide: 37
PRACTICE
Exercise 7: Calculate phone bill
Enter the number of minutes used, knowing that 1 minute costs 1,000
VND.
Print out the total amount to be paid.
Exercise 8: Calculate the number of seconds from hour, minute, second
Enter hour, minute, second. Calculate and print the total number of
seconds.
Total seconds = hour × 3600 + minute × 60 + second
LƯU THỊ THẢO Slide: 38
HOMEWORK
Install VS code and practice exercises 1 - 6 on VS code
LƯU THỊ THẢO Slide: 39