You are on page 1of 16

UNIT1 - Programming

Week [02] – Programming PROCESS

1
Lesson Learning Outcome
Pass Merit Distinction

LO1 Define basic algorithms to carry out an operation and


outline the process of programming an application

P1 Provide a definition of M1 Determine the step taken D1 Examine the


what an algorithm is and from writing code to implementation of an
outline the process in execution. algorithm in a suitable
building an application. language. Evaluate the
relationship between the
written algorithm and the
code variant.

2
Programming Process - Steps

1. Defining the problem

2. Planning the solution

3. Coding the program

4. Testing the program

5. Documenting the program

3
IPO Model – Defining the Problem

▪ Defining the problem consists of:


▪ Identifying what you know (input- given data), and
▪ What you want to obtain (output- the result)

4
Planning the Solution

Two common ways of planning the solution:

1. Draw a flowchart - a flowchart is a pictorial representation


of a step-by-step solution to a problem.

2. Write a pseudocode - English-like nonstandard language


that lets you state your solution. It is more precise than in plain
English but less precise than a formal programming language.

5
Flowchart - Symbols

6
Flowchart & Pseudocode - Example

7
Coding the Program

During this stage you translate the logic expressed in Pseudocode


into a Programming Code. Here you need to adhere to the
language rules called “Syntax”

▪ Syntax – Is like grammar in English, it specifies the correct way


to write statements in the program.

▪ Editor – Programmers usually use a text editor (e.g. Notepad),


which is somewhat like a word processing program, to create a
file that contains the program.

8
Testing the Program
After coding the program, you must prepare to test it on the computer. This
step involves these phases:
▪ Desk checking – You simply sit down and mentally trace, or check, the
logic of the program to attempt to ensure that it is error-free and workable
▪ Translating – Translator checks the syntax of your program giving you all
the syntax-error messages and then translates your program into a form
the computer can understand
▪ Debugging – Detecting, locating, and correcting bugs (mistakes), usually
by running the program

9
Desk Checking - Example

Following pseudocode is expected to find the


sum of numbers from 1 to 5. Desk check this Step Count <= 5 Count Sum Output
code and comment on its correctness. Initial 1 0
1. Count = 1 Iteration 1 True 2 2
2. Sum = 0 Iteration 2 True 3 5
3. While Count <= 5 Iteration 3 True 4 9
4. Count = Count + 1 Iteration 4 True 5 14
5. Sum = Sum + Count Iteration 5 True 6 20

6. End While Iteration 6 False 20

7. Output Sum

10
Translating

▪ Source module – Original


program, is called a source
module.

▪ Object module – Once


translated by a compiler is
called object module.

▪ Load module – After


prewritten programs are
linked from a system library
results in a load module.

11
Documenting the Program

▪ Documentation helps us to understand the programs and systems.


▪ Helps immensely in future maintenance.
▪ Consist of Internal Documentation and External documentation.
▪ Internal Documentation includes: Comments & Meaningful data names
▪ External documentation includes:
▪ A brief narrative description of the program
▪ Logic tools such as flowcharts and pseudocode
▪ Data-record descriptions, program listings
▪ Testing results

12
First Python Program

▪ Running the program interactively using Python interpreter


1. Press windows key and type python
2. Select Python 3.8 from the window and launch the interpreter (Python shell)
3. Type the above program line-by-line which executes that line just as you
press the enter key

13
Running Python as a File
These are the Steps for saving the Python program as a file and running on the
Command Prompt:
1. Type the program on the Notepad or using any editor and save the file with “.py” extension
(myfirst.py)
2. Open the Command Prompt
3. Set the PATH to the directory where Python was installed by running the following
command
set PATH = %path%;C:\windows\programs\python
4. Change current directory to the directory where the Python program was saved
cd c:\users\dayan\documents\python
5. Now run the Python program by typing the following on the Command Prompt
python myfirst.py

14
Detecting Syntax Errors

▪ Make a slight change to the above program by changing line 4 as


follows (Note that now variable total is started with a capital “T”.
▪ print (“Total = “,Total)
▪ After saving the program again and if you run it on the Command
Prompt, the following error message will appear:

15
Lesson Summary

▪ Programming Process - Steps


▪ Defining the Problem
▪ Planning the Solution
▪ Coding the Program
▪ Testing the Program
▪ Documenting the Program
▪ First Python Program

16

You might also like