0% found this document useful (0 votes)
1 views

8011E014 _w1_Python_intro

Uploaded by

tranthihuong
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)
1 views

8011E014 _w1_Python_intro

Uploaded by

tranthihuong
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/ 33

Basic Computer Programming Taipei Medical University

Course ID: 8011E014 College of Medicine

Introduction to Python Programming


Khanh Lee
(黎阮國慶)
What is Programming?
• Programming is the process of
creating instructions for
computers to perform tasks.
• Code: A set of instructions
written in a programming
language.
• Programs: A collection of code
that performs a specific task.

2
Why Learn Programming?
• Automation of tasks (e.g., data processing).
• Problem-solving and logic development.
• Applicable in various industries: web
development, AI, finance, etc.

3
Understanding Algorithms
• Definition: An algorithm
is a step-by-step
procedure for solving a
problem or
accomplishing a task.
• Importance: Algorithms
are the foundation of
programming; they help
us define how a task
should be executed.

4
What Makes a Good Algorithm?
• Clear & Unambiguous: Each step should be easily
understood.
• Well-Defined Inputs & Outputs: Know what you start
with and what you expect at the end.
• Finite: It should terminate after a set number of
steps.
• Efficient: Use resources (time, memory) effectively.

http://sunsite.uakom.sk/sunworldonline/swol-09- 5
1995/swol-09-cockcroft.html
What is Pseudocode?
• Definition: Pseudocode is a plain-language
description of the steps in an algorithm.
• Why Use Pseudocode?: Helps plan your program
before writing actual code. It’s a bridge between
human logic and programming syntax.
• Characteristics: No strict syntax, easy to read, and
closer to human language than code.
Step 1: Start
Step 2: Declare two variables, a and b
Step 3: Set values for a and b
Step 4: Calculate sum = a + b
Step 5: Display sum
Step 6: End
6
Key Takeaways
• Programming is about giving instructions to solve
problems.
• Algorithms are structured ways to solve problems.
• Pseudocode helps bridge the gap between problem-
solving and coding.

7
PYTHON PROGRAMMING

8
What is Python?
• Definition: Python is a high-level, interpreted
programming language known for its readability
and simplicity.
• Key Features:
• Easy to learn and use, with a clean syntax.
• Supports multiple programming paradigms (e.g.,
procedural, object-oriented, and functional
programming).
• Widely used in web development, data analysis,
machine learning, automation, etc.

9
Why Python?
• Easy to Learn and Use
• Supportive Community
• Hundreds of Libraries
and Frameworks
• Versatility, Efficiency,
Reliability, and Speed
• Big data, Machine
Learning and Cloud
Computing
• Academic
Setting Up Python
• https://www.python.org
• Download & install
• Anaconda: https://www.anaconda.com
• Directly: https://www.python.org/downloads/
• To check whether Python is installed or not:
• python –version
• Run Python:
• “python”
• exit()
Running Python script
• Interactive mode programming
• Interpretation in command line
• python script.py
• Jupyter Notebook
• On local computer
• Google Colab
• Spyder
Tips for Programming Beginners
• Tip 1: Start Small, Think Big
• Begin with small, simple programs and work your way
up to more complex projects. Master the basics before
jumping into advanced topics.
• Tip 2: Break Problems into Smaller Steps
• Programming is like solving a puzzle. Break down
problems into smaller, manageable tasks, and solve
them one by one.
• Tip 3: Practice, Practice, Practice
• The more you code, the better you become. Write
code regularly to develop your programming skills.

13
Tips for Programming Beginners
• Tip 4: Learn to Debug
• Debugging is a crucial part of programming. Don’t get
frustrated by errors—learn to troubleshoot and fix
problems.
• Tip 5: Read and Understand Other People’s Code
• Reading other people’s code can teach you new
techniques and best practices.
• Tip 6: Use Online Resources
• Don’t be afraid to seek help. Use online resources like
forums, documentation, and coding platforms.

14
Learn More About Python
• Recommend beginner-friendly resources:
• Python’s official documentation
• Codecademy or freeCodeCamp for Python tutorials
• Stack Overflow for problem-solving.

15
Notice before start
• Indentation 1st level

• Comments 2nd level


• Single line
• Multiple lines 2nd level

• Variables 3rd level

• Single variable
• Multiple variables
• Output variables
Your First Python Program
• Indentation • Comments
• Single line

• Multiple lines
Working with Variables and Data
Types
Variables are containers for storing data values.
Single variable Multiple variables

Output variables

18
Data Types
• Using type() to show data types

• Data Types
Text str
Numeric int, float, complex
Sequence list, tuple, range
Dictionary dict
Set set, frozenset
Boolean Bool
Getting Input from the User
• Use the input() function to get input from users.

20
Basic Operators
Arithmetic Comparison

Operator Name Example Operator Name Example

+ Addition x+y == Equal x == y


!= Not equal x != y
- Subtraction x-y
> Greater than x>y
* Multiplication x*y
< Less than x<y
/ Division x/y >= Greater than or x >= y
equal to
% Modulus x%y
<= Less than or x <= y
equal to
** Exponentiation x ** y

// Floor division x // y
PROGRAMMING FLOW CONTROL

22
If, Else, and Elif Statements
• if-else statements for
decision-making
• Comparison operators
Condition
• Return True or False
False
Operator Name Example True
== Equal x == y
!= Not equal x != y Condition code

> Greater than x > y


< Less than x<y
>= Greater than x >= y
or equal to
<= Less than or x <= y
equal to

23
If, Else, and Elif Statements

if if … elif if … elif … else

nested if
optimized if

24
While loop

• Execute a set of statements as long as a condition is true


Enter normal while break continue
loop
False
Condition

True

Statements

25
For loop

• Iterating over a Enter


sequence loop
True
• List Las item
reached

• Dictionary
False
• String
Statements

26
For loop

Loop in list Loop in string

Loop with 2 arguments Loop with ZIP

27
String Data Type

• Define using single


quotation marks, or
double quotation
marks

• Display using print()


function

• Get items from string


using index & slice

28
Index & Slice
• The indexes in Python start with 0
• The first element has index 0, and the second has
index 1, ...
S[0] = A
S= A B C D E F G H I J
S[1] = B
0 1 9

S[0:3] = ABC
String Methods
• upper, lower, capitalize
• upper() - Converts a string into upper case
• lower() - Converts a string into lower case
• capitalize() - Converts the first character to upper case
• startswith: Returns true if the string starts with
the specified value
• string.startswith(value, start, end)
• endswith: Returns true if the string ends with the
specified value
String Methods
• Strip(): Returns a trimmed version of the string
• string.strip(characters)
• rstrip(), lstrip()
• Concatenate
• Format()
• Escape character
String Methods
• split(): Splits the string at the specified separator,
and returns a list
• string.split(separator, maxsplit)
• join(): Joins the elements of an iterable to the end
of the string
• string.join(iterable)
Q&A
Feel free to raise any questions!

You might also like