Engineering 1D04 Notes
Chapter 2 – Writing Simple Programs
2.1 The Software Development Process
Steps to writing programs:
o Analyze the problem – figure out the problem and what you are doing
o Determine Specifications – describe what your program will do.
o Create a Design – determine the how. Formulate the structure.
o Implement a Design – translate the design into a computer.
o Test / Debug the program – fix any errors by running the program.
o Maintain the program – develop the program in response to the user’s needs.
Debugging – the process of locating and fixing errors.
2.3 Elements of Programs
These are given to modules and the functions within modules.
They are known as identifiers.
Identifiers are case-sensitive.
Reserved Words – identifiers that are part of python itself. They are part of Python and cannot
be used as identifiers.
These are the fragments of code that produce or calculate new data values.
Literal – the simplest kind of expression.
They indicate a specific value.
Spaces are irrelevant within an expression.
Operators are +, -, *, etc…
2.4 Output Statements
There are rules for syntax (form) and semantics (meaning).
Meta-languages are sophisticated notations that describe programming languages.
An expression that doesn’t produce a number but rather a sequence of character data is called a
2.5 Assignment Statements
The variable is the identifier. The variable can be assigned multiple times.
Input statements get information from the user and store it into a variable.
Input is accomplished by using an assignment statement combined with a special expression
called input. = input()
Prompt is usually a string literal. (text inside quotations).
The input is like a delayed expression.
, = ,
This calculates several variables at a time.
A way of swapping work is to introduce a temporary variable. Or just do simultaneous
2.6 Definite Loops
Programmers use loops to execute a sequence of statements several times in successions. The
simplest kind is the definite loop.
Counted loop: given a range to iterate the program
For loop: for in :
Loop index: is the variable after the keyword for.
Sequence: consists of a