You are on page 1of 20

Python Programming for Data Analysis

Lecture 1 - Computers, Programming and Algorithms

Vinh Vo (Ph.D)

Department of Economic Mathemetics


Ho Chi Minh city University of Banking

January 29, 2023

Vinh Vo (EM@HUB) Lecture 1 - Programming overview January 29, 2023 1 / 20


Outline

1 Introduction to computers and programs

2 Algorithms

3 Exercises

Vinh Vo (EM@HUB) Lecture 1 - Programming overview January 29, 2023 2 / 20


Introduction to computers and programs

Outline

1 Introduction to computers and programs

2 Algorithms

3 Exercises

Vinh Vo (EM@HUB) Lecture 1 - Programming overview January 29, 2023 3 / 20


Introduction to computers and programs

Overview of computers

Definition
A computer is a machine that can be programmed to carry out sequences
of arithmetic or logical operations (computation) automatically [wikipedia]
được lập trình để thực hiện các 1
cách chủ động

What does a computer do?


Fundamentally:
performs calculations: a billion calculations per second!
remembers results: 100s of gigabytes of storage!
What kinds of calculations?
built-in to the language
ones that you define as the programmer
computers only know what programmers tell them

Vinh Vo (EM@HUB) Lecture 1 - Programming overview January 29, 2023 4 / 20


Introduction to computers and programs

Computer components

Vinh Vo (EM@HUB) Lecture 1 - Programming overview January 29, 2023 5 / 20


Introduction to computers and programs

Basic machine architecture

Vinh Vo (EM@HUB) Lecture 1 - Programming overview January 29, 2023 6 / 20


Introduction to computers and programs

Why do we program?

We - human beings usually cause errors, quickly forget something and


are not tenacious

Computer programs can perform a set of tasks once we define them


clearly
We can use a computer to solve our regular problems by providing it
clear instructions rather than solving it by our self with many benefits:

1 It makes regular processes much easier


2 It reduces the chance of errors
3 It provides extra analysis of data
4 ...

Vinh Vo (EM@HUB) Lecture 1 - Programming overview January 29, 2023 7 / 20


Introduction to computers and programs

Computer program (1/2)

Programming
The process of using a language that a machine can understand in order to
get it to perform various tasks. Computer programming is how we
communicate with machines in a way that makes them function how we
need.

Computer program
A sequence or set of instructions in a programming language for a
computer to execute.

Vinh Vo (EM@HUB) Lecture 1 - Programming overview January 29, 2023 8 / 20


Introduction to computers and programs

Computer program (2/2)


One component of softwares
Exists in human-readable form is called source code.
Source code is translated into machine language (a string of bits).
compilation
interpretation

Vinh Vo (EM@HUB) Lecture 1 - Programming overview January 29, 2023 9 / 20


Algorithms

Outline

1 Introduction to computers and programs

2 Algorithms

3 Exercises

Vinh Vo (EM@HUB) Lecture 1 - Programming overview January 29, 2023 10 / 20


Algorithms

Algorithms

Definition
a well-defined, systematic logical approach that comes with a step-by-step
procedure for computers to solve any given program.

Properties of algorithms:
effectiveness
definiteness
finiteness
generality

Representation of algorithms:
pseudocode
flowchart
Vinh Vo (EM@HUB) Lecture 1 - Programming overview January 29, 2023 11 / 20
Algorithms

Algorithm representation: Pseudo-code

Pseudocode
A plain language description of the steps in a computing process or an
algorithm. It is often written in a normal language which is intended for
human reading rather than machine reading [wikipedia].

Example: Calculate the absolute value of an integer inputted from


the keyboard.

Algorithm 1: Calculate the absolute value of an integer x


Input: An integer x from user input
Output: The absolute value of x
1 Prompt the user for an integer value
2 Accept that integer and store it in x
3 if x is negative then
4 x = −x
5 Display x

Vinh Vo (EM@HUB) Lecture 1 - Programming overview January 29, 2023 12 / 20


Algorithms

Algorithm representation: Flowchart (1/2)

Use symbols to describe the flow of a program.

Basic symbols:

Start or An oval represents a A diamond represents


End start or an end point a decision

input or A parallelogram A polygon represents off-


output represents input or output page connectors

A rectangle represents a A circle represents connectors.


process
process It is usually used with arrows

An arrow shows relationships


between shapes

Vinh Vo (EM@HUB) Lecture 1 - Programming overview January 29, 2023 13 / 20


Algorithms

Algorithm representation: Flowchart (2/2)

Example: display the flowchart for calculating the absolute value of


an integer x inputted from the keyboard.

input an
Start
integer

store the
integer into 𝑥

Yes
𝑥 < 0?

No 𝑥 = −𝑥

End output 𝑥

Vinh Vo (EM@HUB) Lecture 1 - Programming overview January 29, 2023 14 / 20


Exercises

Outline

1 Introduction to computers and programs

2 Algorithms

3 Exercises

Vinh Vo (EM@HUB) Lecture 1 - Programming overview January 29, 2023 15 / 20


Exercises

Exercises: Electricity Bill

Exercise 1: write a Python program which


allows users to input electricity unit charges.
It calculates the bill (in 1000 VND)
according to the given condition:
For first 50 units 1.5 VND/unit
For next 100 units 2.0 VND/unit
For next 100 units 2.5 VND/unit
For unit above 250 3.0 VND/unit

Vinh Vo (EM@HUB) Lecture 1 - Programming overview January 29, 2023 16 / 20


Exercises

Exercises: Vending Machine

Exercise 2: write a Python program to simulate a Vending Machine


(“Jido Hanbaiki” in Japanese) which sales the beverage list as below:

Name Coke Pepsi Water Sprite Lemonade


Price $0.5 $0.5 $0.3 $0.6 $0.8

Vinh Vo (EM@HUB) Lecture 1 - Programming overview January 29, 2023 17 / 20


Exercises

Simple Equation: ax + b = 0

Exercise 3: write a Python program to solve the equation ax + b = 0.


The solutions will be printed out depending on two real numbers a
and b which are inputted from keyboard.

The flowchart is given as below

Vinh Vo (EM@HUB) Lecture 1 - Programming overview January 29, 2023 18 / 20


Exercises

Quadratic Equation: ax2 + bx + c = 0

Exercise 4: write a Python program to solve the equation


ax2 + bx + c = 0. The solutions will be printed out depending on three
real numbers a, b and c which are inputted from keyboard.

The pseudo-code is given as below

Vinh Vo (EM@HUB) Lecture 1 - Programming overview January 29, 2023 19 / 20


Exercises

B B B B B

B B B B B

B B
Q&A B B

B B B B B

B B B B B

Vinh Vo (EM@HUB) Lecture 1 - Programming overview January 29, 2023 20 / 20

You might also like