Programming - Notes Summary
(Chapter 8)
8.1.1 Variables and Constants
Variables are named data stores that may change during program execution.
Constants are named data stores that do not change during execution.
Python does not enforce constants—everything is treated as a variable.
8.1.2 Basic Data Types
Common types: Integer, Real/Float, Char, String, Boolean.
Types define how data is stored and manipulated.
Example: 'TRUE' is Boolean, '25.0' is Real, 'a' is Char.
8.1.3 Input and Output
Input typically comes from keyboard or files (e.g. .txt, .csv).
Output must be user-friendly and descriptive.
Inputs default as strings—convert to int() or float() when needed.
8.1.4 Programming Fundamentals
Sequencing: Correct order of operations is essential.
Selection: IF and CASE statements enable decision making.
Iteration: Includes FOR (count-controlled), WHILE (pre-condition), and REPEAT UNTIL
(post-condition) loops.
Totalling: Accumulating values using a variable.
Counting: Tracking number of loop iterations.
String handling: length, substring, upper(), lower().
Operators: Arithmetic (+, -, *, /, **, %, //), Logical (==, !=, >, <), Boolean (and, or, not).
8.1.5 Nested Statements
Nested IFs: Conditional statements within other IFs.
Nested Loops: Loop within a loop, often used for 2D arrays or complex structures.
8.1.6 Procedures, Functions and Parameters
Procedure: Subroutine that does not return a value.
Function: Subroutine that returns a value.
Parameters pass values to functions; can be global or local variables.
8.1.7 Library Routines
Pre-written, reusable code such as MOD, DIV, ROUND, RANDOM.
Examples: ROUND(6.97, 2), RANDOM() generates random number.
8.1.8 Creating a Maintainable Program
Use meaningful variable and function names.
Modularize code using functions/procedures.
Add comments to explain complex logic.
8.2.1 One-dimensional Arrays
Array: Group of data of the same type, accessed by index.
Indexing starts from 0 in most programming languages.
Example in pseudocode: DECLARE MyList[0:2] OF INTEGER.
8.2.2 Two-dimensional Arrays
2D Arrays are like tables or spreadsheets.
Used to store data with rows and columns (e.g., marks in subjects).
Python uses nested lists to represent 2D arrays.
8.3.1 Reading from a File
Use read mode to access file contents.
Typical methods: open(), read(), readline().
8.3.2 Writing to a File
Use write mode to create or overwrite files.
Use write() or writelines() to write content with newline characters.