Chapter 1: Programming Concepts Flashcards

Python-oriented

1
Q

Identifier

A

A unique name for something (e.g. variable, constant, procedure, etc.) within the program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Variable

A

An identifier associated with a specific memory location, used to store data. Its value can change while a program runs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Constant

A

A named value within a program with a fixed value that does not change while the program runs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the benefits of declaring a constant? (2)

A
  1. When its value changes, only the declaration has to be changed
  2. It makes your code easier to read, debug and maintain
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Variable names in Python can… (2)

A
  1. Be of any length

2. Use any upper- or lowercase letters, the underscore and the digits 0—9

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Variable names in Python cannot… (2)

A
  1. Begin with a digit

2. Contain special characters (e.g. +, =), as they already have reserved uses

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Why aren’t variable names beginning with underscores encouraged?

A

A considerable number of names beginning with underscores are already reserved for use by the system

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How would you write “Pascal case” in Pascal case?

A

PascalCase

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How would you write “camel case” in camel case?

A

camelCase

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Data type

A

The type of data stored in a variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does the data type of a variable define? (3)

A
  1. The type of data stored in a variable
  2. How much memory is needed to store it
  3. The operations that can be performed on it
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Integer

A

Data type for whole numbers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Real OR Float

A

Data type for fractional numbers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Character

A

Data type for a single character

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

String

A

Data type for text (over 1 character). Sometimes limited to a length of 255 characters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Boolean

A

A true or false value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How much memory is typically needed to store:

  1. An integer?
  2. A float?
  3. A single character?
  4. A boolean?
A
  1. 2 or 4 bytes
  2. 4 or 8 bytes
  3. 1 byte
  4. 1 byte, although 1 bit would suffice
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Assignment

A

When a variable is given a value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Initialisation

A

Explicitly setting the starting values of variables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Algorithm

A

A series of instructions that solves a specific problem

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What are the three main parts of program flow control?

A
  1. Sequence
  2. Selection
  3. Iteration
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Sequence

A

Where instructions are executed one after another in series

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Selection

A

Where the program executes certain instructions based on a condition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

The two basic selection constructs are…

A
  1. If/else statements
  2. Case statements*

*Do not exist in Python

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Boolean expression

A

An expression that evaluates to true or false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

Logical operators

A

NOT, AND, OR and XOR. Used in conditions and Boolean expressions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

Relational operators

A

Operators that compare two values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

Iteration

A

Where a program executes a group of instructions zero or more times based on a condition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

What are the three types of iteration loop constructs?

A
  1. While
  2. Repeat/until*
  3. For

*Do not exist in Python

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

How many times does each loop construct run?

A

While loops: zero or more times
Repeat/until loops*: at least once
For loops: a specific number of times

*Do not exist in Python

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

Condition

A

A Boolean expression that controls an iteration or selection statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

Structure chart

A

A diagram showing how a code module breaks down into smaller modules through sequence, selection and iteration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

Flowchart

A

A diagram using commonly defined symbols to express an algorithm

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

Pseudocode

A

A way of writing an algorithm using programming constructs, but not in an actual language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

Data abstraction

A

The process of taking away characteristics from a program in order to reduce it to a set of essential characteristics

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

Procedure

A

A self-contained section of code that performs a specific task and doesn’t return a value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

Function

A

A self-contained section of code that always returns a value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

What are the benefits of using functions? (6)

A
  1. Different people can work on different modules at the same time
  2. Modular structure is easier to follow, making the code easier to read
  3. Code modules can be reused elsewhere in the program but only need writing once
  4. Modular code is easier to write and debug, reducing programmer error
  5. Modules are easier to update and maintain in the future - you only have to change one part
  6. Modules can have test suites, making them easier to debug
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

Built-in functions

A

Pre-written functions which are provided by the programming language to give standard functionality

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

What are the benefits of using built-in functions? (3)

A
  1. They are pre-written, thus saving time
  2. They have been extensively tested already, which means that they are less likely to contain erroneous code
  3. They are written by expert users, and are therefore likely to use a more efficient algorithm
41
Q

Method

A

A function associated with a particular data type

42
Q

Parameter

A

A variable name declared in the function definition. It is passed a value when the function is called

43
Q

Argument

A

A value passed to a function when it is called

44
Q

Return value

A

The result that is returned from a function

45
Q

Variable scope

A

The amount of the program in which a variable is recognised and can be used

46
Q

Global variable

A

A variable declared in the main part of the program that can be accessed anywhere in the program

47
Q

Local variable

A

A variable declared within a function and which can only be accessed inside said function

48
Q

What are the rules when it comes to variable scope? (3)

A
  1. Always declare variables as locally as possible, as local variables are used over global variables
  2. Only declare variables globally if they are used in more than one function
  3. Declare as few variables globally as possible, as they can be hard to keep track of
49
Q

What is the scope of variables used to control loops in Python?

A

Local to the function the loop is written in

50
Q

What are the three main types of errors?

A
  1. Syntax
  2. Logic
  3. Runtime
51
Q

Syntax error

A

An error in the format of program statements

52
Q

Syntax

A

A set of rules defining how program statements must be written in order for them to be understood by the translator

53
Q

What are some examples of common syntax errors? (4)

A
  1. Mistyping a keyword
  2. Missing keywords out from constructs
  3. Leaving brackets open
  4. Using the incorrect number of parameters
54
Q

Logic error

A

An error in the algorithm logic that means that it does not work as expected, even though it runs

55
Q

What are some examples of common logic errors? (3)

A
  1. Missing brackets out of mathematical calculations
  2. Loops that run the incorrect number of times
  3. Initialising variables in the wrong place
56
Q

Runtime error

A

An unhandled error raised in runtime, which is outside of the control of your program

57
Q

What are some examples of common runtime errors? (4)

A
  1. The user entering input of the wrong data type
  2. Trying to open a file that no longer exists
  3. Trying to read from an empty file
  4. The computer running out of memory
58
Q

Error handling

A

Coding that protects the program from runtime errors by pre-empting possible errors triggered by issues beyond the scope of the program code

59
Q

What is the syntax used for error handling in Python?

A

try:

except:

60
Q

Trace table

A

A manual way of tracking an algorithm by following the changing values of variables throughout the code

61
Q

IDE

A

Integrated Development Environment: a programming environment which provides features such as code editing, debugging help and runtime diagnostics

62
Q

How can a programmer check to make sure their code is error-free? (3)

A
  1. Use trace tables to manually track variable changes
  2. Set break points using an IDE to step into the code and track variable changes
  3. Create a test suite to ensure the code works as expected
63
Q

Text file

A

A file that is structured in lines and only contains ASCII characters

64
Q

Comma Separated Value file

A

A text file with multiple values on each line of text, which are separated by commas

65
Q

AQA Pseudocode to do with text files:

  1. Reading from a file
  2. Writing to a file
  3. Going through a file
  4. Opening a file
  5. Closing a file
A
  1. text ← READLINE(filename, lineNo)
  2. WRITELINE(filename, lineNo, text)
    3*. WHILE NOT eof(filename) …
  3. OPEN filename to read/write
  4. CLOSE filename

*eof = End Of File

66
Q

What are the steps to read from a text file? (4)

A
  1. Give the program a file address
  2. Open the file to read from it (opens the file with a pointer pointing at the first line)
  3. Read a line/lines of text from the file (the pointer is automatically moved down to the next line)
  4. Close the file as soon as possible
67
Q

What are the steps to write to a text file? (4)

A
  1. Open the file to write to
  2. The pointer reads all lines until the End of File so that the file can be added to
  3. When editing a line, the new line is written over the old one
  4. Close the file at the end
68
Q

What kind of error is caused by an unclosed file?

A

A runtime error

69
Q

Database

A

A structured collection of related data

70
Q

State whether the following can be accessed using a text editor:

  1. A text file
  2. A CSV file
  3. A database
A
  1. Yes
  2. Yes
  3. No
71
Q

State whether the following could be accessed using certain spreadsheet or database programs:

  1. A text file
  2. A CSV file
  3. A database
A
  1. No
  2. Yes - each line is a record, and each value between commas a field
  3. Yes
72
Q

When would using a text file be a better choice than using a relational database? (4)

A
  1. When the data is fairly simple and has to be edited by novice users
  2. When the data is simple and the features of a relational database would just take up more space
  3. To avoid compatibility issues - text files are universally readable
  4. When file size is a concern
73
Q

API

A

Application Programming Interface: the interface provided by operating systems to help programmers create applications that run on it (e.g. library programs)

74
Q

Library program

A

The systems software provided by the operating system so that application programmers don’t have to rewrite basic functionality

75
Q

What are the benefits of using library programs? (4)

A
  1. They perform standard functionality in a way users expect it to
  2. Saves time - already written
  3. They have already been tested extensively
  4. Can be called anywhere in your program
76
Q

Open Source program

A

A program that is created using free software that allows free access to the source code

77
Q

The Open Source Initiative License states that… (3)

A
  1. Software is licensed for use, but there is no charge i.e. it can be used by anyone
  2. Software must be distributed with the source code so anyone can modify it
  3. Any derived software must also be distributed under the same license
78
Q

Pros and Cons of using Open Source software (2 | 2)

A

Pros

  1. The software is free to use
  2. Saves time - the code just has to be adapted accordingly

Cons

  1. You cannot guarantee that the code works
  2. They may not be much support for the program you are adapting
79
Q

Data structure

A

A temporary structure in main memory which stores related data items together to form a set of data while a program runs

80
Q

Array

A

A collection of data items of the same data type, grouped under a single identifier

81
Q

2-dimensional array

A

An array made up of 1-dimensional arrays. Used to add rows

82
Q

What is the syntax used to access nested values within a 2-dimensional array?

A

array_name[iexp1][iexp2]

83
Q

Examples of sequence data structures include… (4)

A
  1. Arrays
  2. Strings
  3. Tuples
  4. Lists

*#3 onwards is Python-specific

84
Q

What are the benefits of using sequence data structures? (3)

A
  1. Makes your code easier to read, debug and maintain
  2. Easily processed using a loop, especially a for loop
  3. Allows more efficient access to the data
85
Q

Subscript OR Index

A

The numerical reference to a single data item within a sequence data structure

86
Q

What is the syntax used to access values in a sequence data structure?

A

sequence[iexp]

87
Q

What number does indexing start at in:

a. Pseudocode?
b. Python?

A

a. 1

b. 0

88
Q

Python data structures include… (4)

A
  1. Lists
  2. Tuples
  3. Dictionaries
  4. Classes
89
Q

State the kind of brackets used to denote the following Python data types:

  1. Lists
  2. Tuples
  3. Dictionaries
A
  1. Square brackets
  2. Parentheses
  3. Curly braces
90
Q

List

A

A list of values, not necessarily all of the same data type, which is mutable

91
Q

Tuple

A

Similar to lists, but are immutable

92
Q

Why might someone use a tuple instead of a list? (2)

A
  1. Tuples are faster

2. They use up less memory space

93
Q

Dictionary

A

An index of unique keys, where each key is associated with a value

94
Q

Class

A

A user-defined prototype for a data structure, which can include functions

95
Q

Why might you use a class?

A

Classes help to enclose functions and their relevant data, aiding data abstraction and readability. This becomes more crucial as a program gets larger

96
Q

State whether the following are inherently ordered:

  1. List items
  2. Tuple items
  3. Dictionary items
  4. Class attributes
A
  1. Yes
  2. Yes
  3. No
  4. No
97
Q

Mutable

A

Describes an object whose value can change

98
Q

Immutable

A

Describes an object whose value is unchangeable after being created

99
Q

State whether the following are mutable or immutable:

  1. Lists
  2. Tuples
  3. Strings
  4. Numbers (Integers and Floats)
  5. Dictionaries
A
  1. Mutable
  2. Immutable
  3. Immutable
  4. Immutable
  5. Mutable