CHAPTER 1 & 2
INTRODUCTION TO
COMPUTER
PROGRAMMING&
PROGRAMMING LANGUAGE
BCI1103 Computer Programming (SFK)
OUTCOME:
To know basic information about computer programming
To get familiar with algorithm, pseudo-code and flowchart
To know computer programming language
BCI1103 Computer Programming (SFK)
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.
BCI1103 Computer Programming (SFK)
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
BCI1103 Computer Programming (SFK)
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
BCI1103 Computer Programming (SFK)
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
BCI1103 Computer Programming (SFK)
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: User enter Final Grade of students
1. Calculate Average
2. Check student mark if lower or higher than 50
Output: output fail or pass
BCI1103 Computer Programming (SFK)
INTRODUCTION TO
COMPUTER PROGRAMMING Start
Task:
Write an algorithm to Enter width,
calculate an area based on a length
given width and length. The
area is width multiply
length.
Area = width x length
Flowchart
Print area
BCI1103 Computer Programming (SFK)
End
INTRODUCTION TO COMPUTER
PROGRAMMING
Flowchart symbols that
represent certain meaning
BCI1103 Computer Programming (SFK)
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
BCI1103 Computer Programming (SFK)
COMPUTER PROGRAMMING
LANGUAGE
Python Script
Write code in here
Variables (name, value)/
Help/ Notes
Shell
Input /(SFK)
BCI1103 Computer Programming 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
BCI1103 Computer Programming (SFK)
COMPUTER PROGRAMMING
LANGUAGE: STEPS TO DO
PYTHON CODE IN THONNY The output will be displayed in the Shell
BCI1103 Computer Programming (SFK)
COMPUTER PROGRAMMING LANGUAGE:
STEPS TO DO PYTHON CODE IN THONNY
Pseudo-code:
Input: width, length
1. area = width * length
2. print area
Output: area
BCI1103 Computer Programming (SFK)
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.
BCI1103 Computer Programming (SFK)
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.
BCI1103 Computer Programming (SFK)
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.
BCI1103 Computer Programming (SFK)
GENERAL CONCEPT IN PROGRAMMING
Identifiers: to name variables
Formed by combining letters, digits and underscore
Case sensitive.
2 categories:-
Standard
User-defined
BCI1103 Computer Programming (SFK)
GENERAL CONCEPT IN PROGRAMMING
Identifiers: to name variables
• print
• if digits and underscore
Formed by combining letters,
Case sensitive. • else
2 categories:- • continue
Standard • True
User-defined • False
• while
• break
………….. Python keywords already have in python that have
specific function/instruction
BCI1103 Computer Programming (SFK)
Programmer (you) can define it.
GENERAL
• width CONCEPT IN PROGRAMMING
• length
Identifiers: to name
• area
variables
• firstName
Formed by combining letters, digits and underscore
Case sensitive. • lastName
2 categories:- The rules:
Standard 1. Variables can be a combination of letters in lowercase (a to z) or uppercase
User-defined (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: ! @ # $ % ^ & * ( ).
5. Must be meaningful: first_Name, not nm;
BCI1103 Computer Programming (SFK)
ARITHMETIC OPERATORS
BCI1103 Computer Programming (SFK)
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
BCI1103 Computer Programming (SFK)
EXAMPLE 1: FIND TOTAL VALUES
BCI1103 Computer Programming (SFK)
EXAMPLE 2: FIND DIFFERENCE VALUE
What if?:
BCI1103 Computer Programming (SFK)
EXAMPLE 3: FIND FORCE ON A MASS
force = mass x gravity
BCI1103 Computer Programming (SFK)
EXAMPLE 4: FIND VOLUME OF A CYLINDER
volume = pi x height x radius2
What if?:
BCI1103 Computer Programming (SFK)
PYTHON TUTORIAL
https://www.programiz.com/python-programming
https://www.tutorialspoint.com/python/index.htm
https://www.w3schools.com/python/
BCI1103 Computer Programming (SFK)
BCI1103 Computer Programming (SFK)