0% found this document useful (0 votes)
13 views62 pages

Python Programming Course Overview

The document provides an introduction to a Python programming course, covering topics such as programming basics, Python installation, and running programs. It emphasizes the importance of Python in e-commerce for data analysis and customer satisfaction. The course includes midterm and final evaluations, along with recommended resources for learning Python.

Uploaded by

Nguyen Thu Thao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views62 pages

Python Programming Course Overview

The document provides an introduction to a Python programming course, covering topics such as programming basics, Python installation, and running programs. It emphasizes the importance of Python in e-commerce for data analysis and customer satisfaction. The course includes midterm and final evaluations, along with recommended resources for learning Python.

Uploaded by

Nguyen Thu Thao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 62

Introduction

TS. Trần Vũ Hoàng


Outlines
• Basic introduction to Course
• Introduction to Programing
• Introduction to Python
• Python Installation Guide
• How You Run Programs
• Inside a Python program
NỘI DUNG

q Kiến thức cơ bản về ngôn ngữ lập trình Python

q Các thư viện hỗ trợ Python

q Phát triển các ứng dụng bằng ngôn ngữ Python


YÊU CẦU
KIỂM TRA ĐÁNH GIÁ

qGiữa kỳ: 50%


üChuyên cần
üBài tập trên lớp
üBài tập về nhà
üBáo cáo Project Proposal

qCuối kỳ: 50%


ü Tiểu luận nhóm (cuốn báo cáo, chạy và đánh giá kết quả mô hình)
TÀI LIỆU
- Tài liệu học tập
1. Learning Python - Fourth Edition, Mark Lutz, O’Reilly Publisher, 2009
2. Programming in Python 3 – Second Edition, Mark Summerfield, Addison-
Wesley, 2009
3. Python Cơ Bản, Võ Duy Tuấn
LIÊN HỆ
• GV: Trần Vũ Hoàng
• Email: hoangtv@[Link]
• Số điện thoại: 0988757515
• Liên hệ: Phòng bộ môn Cơ sở Kỹ thuật Điện tử (Khu C), Khoa Điện - Điện
Tử
• Homepage: [Link]
Why?
• What is E-Commerce?
• Why does the E-commerce industry need to learn python?
E-Commerce
Why?
• Collect a lot of data from users without hindering the customer experience
• Customer satisfaction should be a top concern in E-Commerce à need to
know the customer and their preferences.
• Data science:
• Product recommendations for users.
• Analyze trends and customer behavior
• Forecast sales and logistics.
• Optimize product prices and payment methods.
Product recommendations
Product recommendations
Why?
Why?
• Python is Open-source
• You don’t need to pay anything to use it
• Python runs on Linux, which is also open-source
• Easy to Learn
• Has one of the shortest learning curves when compared to other languages
• Python is fast
• Developers take less time to write more code when compared to other computer
languages
• You can get a new developer in the middle of the project without slowing the
development process down
• Python is Scalable
• You might start with a few product and website visitors and then increasing suddenly
Outlines
• Basic introduction to Course
• Introduction to Programing
• Introduction to Python
• Python Installation Guide
• How You Run Programs
• Inside a Python program
Introduction to Programing
• Algorithms: procedure in terms of
• Actions to be executed
• The order in which these actions are to
be executed
Introduction to Programing
• Pseudo-code:
• Artificial, informal language that helps us develop algorithms
• Similar to everyday English
• Not actually executed on computers
• Helps us “think out” a program before writing it
Introduction to Programing
• Flowchart: a diagrammatic representation of an algorithm.
Introduction to Programing

Symbol Purpose

Flow line

Terminal(Stop/Start)

Input/Output

Processing

Decision
Introduction to Programing

On-page Connector

Off-page Connector

Predefined Process/Function
Introduction to Programing
Introduction to Programing
• Flowchart:
Outlines
• Basic introduction to Course
• Introduction to Programing
• Introduction to Python
• Python Installation Guide
• How You Run Programs
• Inside a Python program
Introduction to Python
Introduction to Python
• Python 2 is an old open source version here are where you still need to learn
Python 2
• your company’s code written in Python 2
• your development team is working on a project that depends on specific third-party
libraries or software which you are not able to port to Python 3, then Python 2 is the
only option available for you.
• prime reasons for using Python 3.x versions:
• supports modern techniques like AI, machine learning, and data science
• supported by a large Python developer’s community. Getting support is easy.
• Its easier to learn Python language compared to earlier versions.
• Offers Powerful toolkit and libraries
• Mixable with other languages
Introduction to Python
Introduction to Python
Introduction to Python
Introduction to Python
Introduction to Python
Outlines
• Basic introduction to Course
• Introduction to Programing
• Introduction to Python
• Python Installation Guide
• How You Run Programs
• Inside a Python program
Install:
Truy cập web [Link]
Windows:
1

3 5

4 6
2
Linux

1
Download file anaconda Linux

2 Python3: bash ~/Downloads/Anaconda3-2020.02-Linux-x86_64.sh


Open Terminal

Python2: bash ~/Downloads/Anaconda2-2019.10-Linux-x86_64.sh

3
Run:
In order to continue the installation process, please review the license agreement Enter
Do you wish the installer to initialize Anaconda3 by running conda init? Yes
MacOS

1
Download file anaconda MacOS

2 3
Some commonly used commands
Phiên bản python muốn sử dụng
q Kiểm tra version của Anaconda: conda –V / conda --version
q Tạo một enviroment cho một project (dư án): conda create -n yourenvname python=x.x

Tên môi trường muốn đặt


q Kích hoạt (Activate) một enviroment: activate yourenvname

q Thoát khỏi môi trường: conda deactivate


q Xóa một enviroment: conda env remove -n yourenvname
q Kiểm tra các môi trường đã được tạo: conda env list
Some commonly used commands

q Cài đặt thư viện:


+ Cách 1: Thông qua Python có trong môi trường
pip / pip3 install ten_thu_vien
+ Cách 2: Thông qua conda
conda install ten_thu_vien
q Kiểm tra các gói trong env: conda list -n yourenvname

q Tra cứu lệnh cài đặt thư viện: [Link]


Some websites to learn python programming

[Link]
[Link]

[Link]
[Link]
Some websites to learn python programming

[Link]
Outlines
• Basic introduction to Course
• Introduction to Programing
• Introduction to Python
• Python Installation Guide
• How You Run Programs
• Inside a Python program
How You Run Programs
• Interactive Prompt:
• Windows: Command Prompt (cmd)
• Mac OS, Linux: Terminal
• The “>>>” is a Python prompt indicating that Python is ready for us to give
it a command. These commands are called statements.
How You Run Programs
• the parentheses here are required in 3.0:

• you don’t usually need to say “print” explicitly at this prompt:


How You Run Programs
• Interactive Prompt:
• Type Python commands only: can only type Python code at the Python prompt, not
system commands
• print statements are required only in files: you must say print in files, but not
interactively
• Don’t indent at the interactive prompt: be sure to start all your unnested statements
in column 1
• Watch out for prompt changes for compound statements
• Terminate compound statements at the interactive prompt with a blank line
• The interactive prompt runs one statement at a time
How You Run Programs
• Interactive Prompt:
• Type Python commands only: can only type Python code at the Python prompt, not
system commands
• print statements are required only in files: you must say print in files, but not
interactively
• Don’t indent at the interactive prompt: be sure to start all your unnested statements
in column 1
• Watch out for prompt changes for compound statements
• Terminate compound statements at the interactive prompt with a blank line
• The interactive prompt runs one statement at a time
How You Run Programs
• Usually we want to execute several statements together that solve a common
problem. One way to do this is to use a function.
>>> def hello():
print("Hello")
print("Computers are Fun")

>>>
• The first line tells Python we are defining a new function called hello.
• The following lines are indented to show that they are part of the hello
function.
• The blank line (hit enter twice) lets Python know the definition is finished.
How You Run Programs
>>> def hello():
print("Hello")
print("Computers are Fun")

>>>
• Notice that nothing has happened yet! We’ve defined the function, but we
haven’t told Python to perform the function!
• A function is invoked by typing its name.
>>> hello()
Hello
Computers are Fun
>>>
How You Run Programs
• What’s the deal with the ()’s?
• Commands can have changeable parts called parameters that are placed
between the ()’s.
>>> def greet(person):
print("Hello",person)
print ("How are you?")

>>>
How You Run Programs
• >>> greet("Terry")
Hello Terry
How are you?
>>> greet("Paula")
Hello Paula
How are you?
>>>
• When we use parameters, we can customize the output of our function.
How You Run Programs
• Interactive Prompt’s disadvantage: programs you type there go away as soon
as the Python interpreter executes them
• need to write your code in files, which are usually known as modules
• module files are often referred to as programs in Python
• a program is considered to be a series of pre-coded statements stored in a file for
repeated execution
• Module files that are run directly are also sometimes called scripts
How You Run Programs
How You Run Programs
# File: [Link]
# A simple program illustrating chaotic behavior
def main():
print("This program illustrates a chaotic function")
x = eval(input("Enter a number between 0 and 1: "))
for i in range(10):
x = 3.9 * x * (1 - x)
print(x)
main()
• We’ll use [Link] when we save our work to indicate it’s a Python
program.
• In this code we’re defining a new function called main.
• The main() at the end tells Python to run the code.
How You Run Programs
>>>
This program illustrates a chaotic function
Enter a number between 0 and 1: .5
0.975
0.0950625
0.335499922266
0.869464925259
0.442633109113
0.962165255337
0.141972779362
0.4750843862
0.972578927537
0.104009713267
>>>
Outlines
• Basic introduction to Course
• Introduction to Programing
• Introduction to Python
• Python Installation Guide
• How You Run Programs
• Inside a Python program
Inside a Python program
# File: [Link]
# A simple program illustrating chaotic behavior

def main():
print("This program illustrates a chaotic function")
x = eval(input("Enter a number between 0 and 1: "))
for i in range(10):
x = 3.9 * x * (1 - x)
print(x)

main()
Inside a Python program
# File: [Link]
# A simple program illustrating chaotic behavior

• Lines that start with # are called comments


• Intended for human readers and ignored by Python
• Python skips text from # to end of line
Inside a Python program
def main():

• Beginning of the definition of a function called main


• Since our program has only this one module, it could have been written
without the main function.
• The use of main is customary, however.
Inside a Python program
print("This program illustrates a chaotic function")

• This line causes Python to print a message introducing the program.


Inside a Python program
x = eval(input("Enter a number between 0 and 1: "))

• x is an example of a variable
• A variable is used to assign a name to a value so that we can refer to it later.
• The quoted information is displayed, and the number typed in response is
stored in x.
Inside a Python program
for i in range(10):
• For is a loop construct
• A loop tells Python to repeat the same thing over and over.
• In this example, the following code will be repeated 10 times.
Inside a Python program
x = 3.9 * x * (1 - x)
print(x)
• These lines are the body of the loop.
• The body of the loop is what gets repeated each time through the loop.
• The body of the loop is identified through indentation.
• The effect of the loop is the same as repeating this two lines 10 times!
Inside a Python program
x = 3.9 * x * (1 - x)

• This is called an assignment statement


• The part on the right-hand side (RHS) of the “=“ is a mathematical
expression.
• * is used to indicate multiplication
• Once the value on the RHS is computed, it is stored back into (assigned) into
x
Inside a Python program
main()

• This last line tells Python to execute the code in the function main

You might also like