Topic 1-Update
Topic 1-Update
Python Programming
CT108-3-1-PYP
TOPIC LEARNING OUTCOMES
Define the
steps in
developing a
At the end of this program:
topic, you should be • define a problem
able to: • outline a solution
using algorithms
• Sequence
• basic
mathematics
CT108-3-1-PYP Introduction to Problem Solving and Algorithm SLIDE 2
Contents & Structure
• Introduction to algorithms
• Program design using pseudocodes and simple notations of flowchart
– Sequence
– basic mathematics
People -> believe -> programmer -> good at mathematics -> have a memory for
figures and technical information -> be prepared to spend many hours sitting at a
computer, typing programs.
Given the right tools and steps to follow -> anyone can write well-designed programs.
Jumping straight into the coding phase without first designing a proper
solution usually results in a program that contains many errors.
What is Problem ?
Here is some examples we face in day-to- Will I get proper transport to go to my workspace ?
Should I wear shoes today ?
day life can be important or can be least Should I go to a movies ?
importance . Which Cell phone should I buy?
When solving problem on the computer , one of the most difficult tasks for the problem
solver is writing the instructions
First steps: underline the nouns and adjectives -> will establish the
input and output components, as well as any objects required.
• Pseudocode
• Flowcharts
set of detailed
It can be defined in programming terms as a Unambiguous
ordered instructions developed
to describe the processes necessary to produce the desired output from a given input.
It is English that has been formalized and abbreviated to look like the high-level computer languages.
No standard pseudocode.
Authors seem to adopt their own special techniques and sets of rules, which often resemble a particular
programming language.
Pseudo code
We do not have to commonly borrows its
No standard for follow any strict syntax Pseudo code vary in syntax from popular
Statements are written
pseudo code syntax like computer style from author to programming
in simple English.
exists programming author languages like C,
language Fortran, Pascal, Java,
Python etc.
Each set of
Groups of statements Keywords and
instructions is written Each instruction is
may be formed into indentation are used
from top to bottom, written on a separate
modules, and that to signify particular
with only one entry line.
module given a name. control structures.
and one exit.
Designing a solution algorithm -> necessary to keep in mind the fact ->
computer -> perform the set of instructions you write.
• A computer can
– receive information. input
– produce information. output
– perform arithmetic.
– assign a value to a piece of data.
– compare two pieces of information process
` and select one of two alternative actions.
– repeat a group of actions.
• Each operation can be represented as a straightforward
instruction in English, with keywords and indentation to signify
a particular control structure.
When a computer is required to receive information or input from a particular source, whether it be
a terminal, a disk or any other device, the verbs are used in the pseudocode.
Usually, a programmer will choose one and stick with it throughout their algorithm.
Read -> used when the algorithm is to receive input from a record on a file
Get -> used when the algorithm is to receive input from the keyboard.
When a computer is required to supply information or output to a device, the verbs are used in
the pseudocode.
Sample of output keywords
• PRINT
• DISPLAY
• SHOW
• OUTPUT
• PUT
Put, Output or Display -> used when output is to be written to the screen
• Compute
• Calculate
Used verbs is allowed • Determine
• Increment; ++ or +=
• Decrement; -- or -=
Example:
1. Start
2. Get A
Execution
3. Get B
sequence
4. Calculate result
C=A*B
5. Display result C
6. End
Instead of writing down our algorithm in some programming language like C, C++, Java,
C#, PHP, Python, Ruby etc. we use flowchart to express our algorithm which gives us a
general view about the algorithm.
Flowchart as the name indicates, is about the flow of execution of our algorithm.
Start
Get A
Get B
Calculate Resut
C=A*B
Display the
Result C
Stop
Start Terminal.
Start Program start
here
Read A Input.
Read B Enter values for
A and B
Calculate Resut
C=A*B Process
Display the
Result C Output
Stop Terminal
Stop Program end
here
1 2
Start
2
1
Yes 1
No Stop
‹#›
This step may need to be performed several times until you are
satisfied that the program is running as required.
• Program documentation
– should not be listed as the last step
– Really an ongoing task from the initial definition of the problem to the final test
result.
• Involves both external documentation (such as hierarchy charts, the
solution algorithm, and test data results) and internal documentation
which may have been coded in the program.
• Program maintenance refers to changes which may need to be made
to a program throughout its life.
• Program -> well designed using structured programming techniques,
the code will be seen as self-documenting, resulting in easier
maintenance.
CT108-3-1-PYP Introduction to Problem Solving and Algorithm SLIDE 39
‹#›
Sequential Structure
• A series of steps or statements that are executed in the order they are
written in an algorithm.
1. Start
2. Statement_1
3. Statement_2
4. Statement_3
n. Statement_n+1
N+[Link]
Input: Read
Length = 5 Length,
Width = 3 Width
Output
Print
Area: 15 Area,
Perimeter
Perimeter: 16
Stop