0% found this document useful (0 votes)
50 views10 pages

Notes - INTRODUCTION TO PROGRAMMING

The document provides an overview of problem solving using algorithms and introduces Python programming. It discusses algorithmic problem solving steps, flowchart symbols, and introduces Python including what it is, why learn it, applications, and the basic programming process. It also covers Python syntax, variables, data types, operators, control flow statements including different loop structures, and examples of input and output.

Uploaded by

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

Notes - INTRODUCTION TO PROGRAMMING

The document provides an overview of problem solving using algorithms and introduces Python programming. It discusses algorithmic problem solving steps, flowchart symbols, and introduces Python including what it is, why learn it, applications, and the basic programming process. It also covers Python syntax, variables, data types, operators, control flow statements including different loop structures, and examples of input and output.

Uploaded by

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

CHAPTER 1

PROBLEM SLOVING…
ALGORITHM
❖ Set of instructions written down to formulate the solution of the problem

(satu set arahan untuk menyelesaikan masalah mengikut aturan)

❖ These solutions are not answers but specific instructions for getting

answers. (Ini merupakan langkah-langkah yang tepat untuk menyelesaikan

masalah bukannya penyelesaian masalah tersebut.)

❖ Uses human native language (ditulis/menggunakan bahasa

pertuturan manusia)

ALGORITHMIC PROBLEM-SOLVING STEPS

❖ Understanding the problem. (Memahami masalah)

❖ Analysing an algorithm. (Menganalisis algoritma)

❖ 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

❖ High-level programming language.

❖ Python created by Guido van Rossum on 20 February 1991.


WHY LEARN PYTHON?
❖ Easy to learn (mudah untuk pelajari)

❖ 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)

❖ Variable (pemboleh ubah/jenis data)

❖ 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 must start with a letter (mesti mula dengan huruf)

❖ Variable cannot start with a number (tidak bolehh mula dengan nombor)

❖ Menggunakan sama pemboleh ubah sepanjang coding, tidak boleh diubah.

❖ Example variable :

Bob_2 bob BOB_2 BobAndy Bob_andy bob_andy

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

yang mengandungi susunan aksara atau symbol.

❖ Integer (int): nombor yang tidak mempunyai pecahan atau perpuluhan.

❖ float: nombor yang mempunyai perpuluhan atau pecahan.

❖ Boolean (bool): data dalam bentuk pilihan iaitu memilih salah satu daripada

sesuatu yang “benar”(true) atau “palsu”(false)


INPUT & OUTPUT
❖ Example of input:
 input(“Key in your name”)
 int (input(“Key in your age”))
 float(input(“Key in your weight in kg”))
❖ Example of output:
 print(‘Welcome to Python programming’)
 print(“Have a nice day”)
 print(‘Thank you’)
Python Operators and Expressions
❖ Arithmetic

 Assume variable x holds the value 10 and variable y holds the


value 21, then
Operator Name Example

+ 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)

 if score < 40:

print (‘see your lecturer’)

 Two alternatives (if...else) (kalau ada 2 pilihan/jawapan)

 if score >= 40:

print(‘pass’)

else:

print(‘fail’)

 Multiple alternatives (if...elif...else / nested if) (kalau ada 2 pilihan ke atas)

 Ada 2 syarat dan banyak pilihan


 if score >= 80:
print('distinction')
elif score >= 40:
print('pass’)
else:
print('fail')

Iteration Structure (Repetition/Loop) ULANGAN


 Fixed repetition (Ulangan yang ditetapkan)
 Variable repetition (Pengulangan pemboleh ubah)

Python Loop Structure

You might also like