0% found this document useful (0 votes)
2 views30 pages

Introduction to Computer Programming

Uploaded by

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

Introduction to Computer Programming

Uploaded by

adamqusairy93
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Chapter 1 & 2

Introduction to Computer Programming


Computer Programming Language
Dr Suryanti Awang, Faculty of Computing
Outcome:

 To know basic information about computer programming


 To get familiar with algorithm, pseudo-code and flowchart
 To know computer programming language

Dr Suryanti Awang, Faculty of Computing


Introduction to Computer
Programming
 Computer programs, known as software, are instructions to the
computer.
 Programming began in the 1940s, using memory addresses and machine
code directly.
 Older programs were “monolithic,” and ran from beginning to end.
 Programs are written using programming languages.
 Newer programs contain modules that can be combined to form
programs.

Dr Suryanti Awang, Faculty of Computing


Introduction to Computer
Programming
1101101010011010
COBOL (COmmon Business Oriented Language)
FORTRAN (FORmula TRANslation)
BASIC (Beginner All-purpose Symbolic Instructional
Code)
Pascal (named for Blaise Pascal)
Ada (named for Ada Lovelace)
C (whose developer designed B first)
Visual Basic (Basic-like visual language developed by
Microsoft)
Delphi (Pascal-like visual language developed by
Borland)
C++ (an object-oriented language, based on C)
Java (an object-oriented language)
Python
Dr Suryanti Awang, Faculty of Computing
Introduction to Computer
Programming
 Algorithm, pseudo-code, flowchart
 Algorithm?  the list of instructions and rules that a computer needs to
do to complete a task
 Algorithm  pseudo-code or flowchart or both
 Pseudo-code?  a plain language description of the steps in an algorithm
 Flowchart?  a diagram that depicts a process, system or computer
algorithm

Dr Suryanti Awang, Faculty of Computing


Introduction to Computer
Programming
 Task:
Write an algorithm to calculate an area based on a given width and
length. The area is width multiply length.

Pseudo-code:
Input
Input: a width and a length
1. Calculate the area by multiplying the width
and length Process

2. Print out the area


Output: area Output

Dr Suryanti Awang, Faculty of Computing


Introduction to Computer
Programming
 Task:
Write an algorithm to determine a student’s final grade and
indicate whether it is passing or failing. The final grade is
calculated based on the average of four marks. If the average
mark is below than 50, the grade is FAIL and vice versa.
Pseudo-code:
Input: width, length
1. area = width * length
2. print area
Output: area

Dr Suryanti Awang, Faculty of Computing


Introduction to Computer Flowchart

Programming Start

 Task:
Write an algorithm to Enter width,
calculate an area based length
on a given width and
length. The area is
width multiply length.
Area = width x
length

Print area

Dr Suryanti Awang, Faculty of Computing


End
Introduction to Computer
Programming
 Flowchart  symbols that represent certain meaning

Dr Suryanti Awang, Faculty of Computing


Computer Programming Language

 Python  Thonny (IDE)


 Script  to write your code
 Shell  to execute the written code
 Variable  to view your variables name and value

Dr Suryanti Awang, Faculty of Computing


Computer Programming Language

Python Script

Write code in here

Variables (name,

value)/ Help/ Notes

Shell
Dr Suryanti Awang, Faculty of Computing
Input / Output displayed

here
Computer Programming Language:
Steps to do Python code in Thonny
 Step 1: Create new file: click File  New  name your file
 Step 2: Write code in the script

 Step 3: Click File  Save or “ctrl+s”


 Step 4: Click Run to execute the code

Dr Suryanti Awang, Faculty of Computing


Computer Programming Language:
Steps to do Python code in Thonny
 The output will be displayed in the Shell

Dr Suryanti Awang, Faculty of Computing


Computer Programming Language:
Steps to do Python code in Thonny
Pseudo-code:
Input: width, length
1. area = width * length
2. print area
Output: area

Dr Suryanti Awang, Faculty of Computing


Dr Suryanti Awang, Faculty of Computing
Computer Programming Language:
Steps to do Python code in Thonny
How the python Shell execute the program?  Line by line in the code

Dr Suryanti Awang, Faculty of Computing


Computer Programming Language:
Steps to do Python code in Thonny
 We cannot see the process on computer screen because the processes
occur in computer memory and CPU (the brain of computer).
 We can see the variables name and the values that have been executed.
 Program execution is ended when there is no more code after the last
line.

Dr Suryanti Awang, Faculty of Computing


Summary:
 Computer program contain codes of instructions, telling computer
what to do.
 The instructions are written by you as the programmer (a person
writing computer codes).
 The written instructions (codes) are stored in files (computer system).
 It is executed (start doing all the actions), when you open or execute
the program in computer system.

Dr Suryanti Awang, Faculty of Computing


General Concept in Programming
 How to write scripts to solve a problem?  do the step by step in
flowchart and pseudo-code
 The steps must be based on the logic to solve the problem.
 Logic Syntax and Semantic logic
 Syntax  formal rules - how valid instructions are written in a
programming language  the code must be written based on valid rules
in the python (eg.: print (“ “))
 Semantic  set of rules that determines the instruction’s meaning in a
programming languages  eg.: to calculate area, you need to have the
width and length value, you cannot write the area calculation before
having the values.

Dr Suryanti Awang, Faculty of Computing


General Concept in Programming
 Identifiers: to name variables
 Formed by combining letters, digits and underscore
 Case sensitive.
 2 categories:-
 Standard
 User-defined

Dr Suryanti Awang, Faculty of Computing


General Concept in Programming
• print
 Identifiers: to name
• variables
if
 Formed by combining• letters,
else digits and underscore
 Case sensitive. • continue
 2 categories:- • True
 Standard • False
 User-defined • while
• break
………….. Python keywords  already have in python
that have specific function/instruction

Dr Suryanti Awang, Faculty of Computing


General Concept in Programming
Programmer (you) can define it.
• width
• length
 Identifiers: to name variables
• area
 Formed by combining letters, digits and underscore
• firstName
 Case sensitive.
• lastName
 2 categories:-
 The rules:
Standard
 User-defined 1. Variables can be a combination of letters in lowercase (a to
z) or uppercase (A to Z) or digits (0 to 9) or an underscore
_. Names like myClass, var_1 and print_this_to_screen,
all are valid example.
2. Cannot start with digit: 1var
3. Cannot use the python keywords.
4. Cannot use special symbols: ! @ # $ % ^ & * ( ).
Dr Suryanti Awang, Faculty of Computing
5. Must be meaningful: first_Name, not nm;
Arithmetic Operators

Dr Suryanti Awang, Faculty of Computing


General Concept in Programming
 Identifiers: to name variables
 Formed by combining letters, digits and underscore
 Case sensitive.
 2 categories:-
 Standard
 User-defined

 Let’s analyze the program

Dr Suryanti Awang, Faculty of Computing


Example 1: find total values

Dr Suryanti Awang, Faculty of Computing


Example 2: find difference value

What if?:

Dr Suryanti Awang, Faculty of Computing


Example 3: find force on a mass
force = mass x gravity

Dr Suryanti Awang, Faculty of Computing


Example 4: find volume of a cylinder
volume = pi x height x radius2

What if?:
Python Tutorial

 [Link]
g
 [Link]
 [Link]

Dr Suryanti Awang, Faculty of Computing


Dr Suryanti Awang, Faculty of Computing

You might also like