Notes - INTRODUCTION TO PROGRAMMING
Notes - INTRODUCTION TO PROGRAMMING
PROBLEM SLOVING…
ALGORITHM
❖ Set of instructions written down to formulate the solution of the problem
❖ These solutions are not answers but specific instructions for getting
pertuturan manusia)
❖ Coding an algorithm.
PROBLEM SOLVING
FLOWCHART SYMBOLS
Symbols Meaning
Terminal (START & END)
begin and end with this symbol.
Input/Output
Input: Read/Get/Prompt
Output: Display/Print
Process
Any process in pseudocode
Example: Calculation
Predefined Process
Can be expanded to include few sub
processes
Decision
There will be options where th logic
needs to decide which path to take
(TRUE & FALSE)(YES & NO)
Flow Lines
Connect various symbols in flowchart.
Arrowhead indicates logic flow of
control.
CHAPTER 2
INTRODUCTION TO PYTHON PROGRAMMING…
WHAT IS PYTHON?
❖ Is a widely-used
❖ Easy to use writing new software, (mudah untuk digunakan untuk membuat
software baharu)
PYTHON APPLICATIONS..
❖ Business applications
❖ Web applications
❖ Software development
Web (online python)
❖ W3schools.com
❖ Programiz.com
❖ REPLIT.com
PYTHON PROGRAMMING PROCESS
❖ ALGORITHM
Flow chart
PSEUDOCODE
❖ PROGRAM
Interpreter / compiler
❖ SOFTWARE
IDLE/ PYTHON SHELL
PYCHARM
SYNTAX
❖ Indentation (penjarakan)
❖ Comment (arahan)
❖ Assignment
TYPES OF ERROR IN PROGRAMMING
❖ Syntax error (ralat sintaks)
Python doesn’t recognize a section of your program as valid Python code.
Kesalahan tatabahasa serperti salah ejaan dan tatatanda
Penggunaan objek atau aksara yang tidak dikenali.
❖ Runtime error (ralat masa larian)
A program that passed the interpreter’s syntax checks, and stared to execute.
Ditemuhi ketika atur cara yang sedang berjalan terganggu.
Pengiraan data bukan berangka, pembahagian dengan digit 0
❖ Logic error (Ralat logik)
When the program runs without crashing, but produces an incorrect result.
Caused by a mistake in the program’s logic.
Berlaku apabila atur cara tidak berfungsi seperti yang diingini.
Ralat logic mengesan melaluhi output yang dihasilkan.
Seperti penjarakan (spacing), formula pengiraan.
VARIABLE NAME & RULE FOR PYTHON VARIABLES
❖ Can have short name like x and y or more descriptive name
(age,carname,total_volume)
❖ Variable cannot start with a number (tidak bolehh mula dengan nombor)
❖ Example variable :
BASIC DATATYPES
Text Type String (str)
Numeric Types Integer(int), float, complex
Sequence Types list, tuple, range
Mapping Types dict
Set Types set, frozenset
Boolean Types bool
Binary Types Bytes, bytearray, memoryview
❖ String (str): data dalam bentuk ruang kosong, teks, perkataan atau nilai
❖ Boolean (bool): data dalam bentuk pilihan iaitu memilih salah satu daripada
+ Addition x + y = 31
- Subtraction x – y = -11
* Multiplication x * y = 210
/ Division y / x = 2.1
% Modulus (baki yg ada) y%x=1
** Power/ exponent x ** x = 10,000,000,000
// Floor division y//x = 2
❖ Assignment
Binding a variable in Python means setting a name to hold a reference to
some object
Assignment creates references, not copies
Names in Python do not have an intrinsic type, objects have types
Python determines the type of the reference automatically based on what
data is assigned to it.
You can assign to multiple names at the same time.
❖ Comparison
These operators compare the values on either side of them and decide the
relation among them; TRUE or NOT TRUE
❖ Logical
CHAPTER 3
CONTROL FLOW STATEMENTS
TYPES OF CONTROL STRUCTURES:
Sequence (Uruthan)
Selection (Pilihan)
Iteration (Ulangan)
Sequence Structure
execution of the program was done line by line from the beginning until the end.
(perlaksanaan atur cara dilakukan baris demi baris dari awal hingga akhir)
Selection Structure
One alternative (if) (kalau ada 1 pilihan/jawapan)
print(‘pass’)
else:
print(‘fail’)