Chapter 1: Programming Concepts Flashcards
Python-oriented
Identifier
A unique name for something (e.g. variable, constant, procedure, etc.) within the program
Variable
An identifier associated with a specific memory location, used to store data. Its value can change while a program runs
Constant
A named value within a program with a fixed value that does not change while the program runs
What are the benefits of declaring a constant? (2)
- When its value changes, only the declaration has to be changed
- It makes your code easier to read, debug and maintain
Variable names in Python can… (2)
- Be of any length
2. Use any upper- or lowercase letters, the underscore and the digits 0—9
Variable names in Python cannot… (2)
- Begin with a digit
2. Contain special characters (e.g. +, =), as they already have reserved uses
Why aren’t variable names beginning with underscores encouraged?
A considerable number of names beginning with underscores are already reserved for use by the system
How would you write “Pascal case” in Pascal case?
PascalCase
How would you write “camel case” in camel case?
camelCase
Data type
The type of data stored in a variable
What does the data type of a variable define? (3)
- The type of data stored in a variable
- How much memory is needed to store it
- The operations that can be performed on it
Integer
Data type for whole numbers
Real OR Float
Data type for fractional numbers
Character
Data type for a single character
String
Data type for text (over 1 character). Sometimes limited to a length of 255 characters
Boolean
A true or false value
How much memory is typically needed to store:
- An integer?
- A float?
- A single character?
- A boolean?
- 2 or 4 bytes
- 4 or 8 bytes
- 1 byte
- 1 byte, although 1 bit would suffice
Assignment
When a variable is given a value
Initialisation
Explicitly setting the starting values of variables
Algorithm
A series of instructions that solves a specific problem
What are the three main parts of program flow control?
- Sequence
- Selection
- Iteration
Sequence
Where instructions are executed one after another in series
Selection
Where the program executes certain instructions based on a condition
The two basic selection constructs are…
- If/else statements
- Case statements*
*Do not exist in Python
Boolean expression
An expression that evaluates to true or false
Logical operators
NOT, AND, OR and XOR. Used in conditions and Boolean expressions.
Relational operators
Operators that compare two values
Iteration
Where a program executes a group of instructions zero or more times based on a condition
What are the three types of iteration loop constructs?
- While
- Repeat/until*
- For
*Do not exist in Python
How many times does each loop construct run?
While loops: zero or more times
Repeat/until loops*: at least once
For loops: a specific number of times
*Do not exist in Python
Condition
A Boolean expression that controls an iteration or selection statement
Structure chart
A diagram showing how a code module breaks down into smaller modules through sequence, selection and iteration
Flowchart
A diagram using commonly defined symbols to express an algorithm
Pseudocode
A way of writing an algorithm using programming constructs, but not in an actual language
Data abstraction
The process of taking away characteristics from a program in order to reduce it to a set of essential characteristics
Procedure
A self-contained section of code that performs a specific task and doesn’t return a value
Function
A self-contained section of code that always returns a value
What are the benefits of using functions? (6)
- Different people can work on different modules at the same time
- Modular structure is easier to follow, making the code easier to read
- Code modules can be reused elsewhere in the program but only need writing once
- Modular code is easier to write and debug, reducing programmer error
- Modules are easier to update and maintain in the future - you only have to change one part
- Modules can have test suites, making them easier to debug
Built-in functions
Pre-written functions which are provided by the programming language to give standard functionality