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
Boolean expression
An expression that evaluates to true or false
26
Logical operators
NOT, AND, OR and XOR. Used in conditions and Boolean expressions.
27
Relational operators
Operators that compare two values
28
Iteration
Where a program executes a group of instructions zero or more times based on a condition
29
What are the three types of iteration loop constructs?
1. While 2. Repeat/until* 3. For *Do not exist in Python
30
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
31
Condition
A Boolean expression that controls an iteration or selection statement
32
Structure chart
A diagram showing how a code module breaks down into smaller modules through sequence, selection and iteration
33
Flowchart
A diagram using commonly defined symbols to express an algorithm
34
Pseudocode
A way of writing an algorithm using programming constructs, but not in an actual language
35
Data abstraction
The process of taking away characteristics from a program in order to reduce it to a set of essential characteristics
36
Procedure
A self-contained section of code that performs a specific task and doesn't return a value
37
Function
A self-contained section of code that always returns a value
38
What are the benefits of using functions? (6)
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
39
Built-in functions
Pre-written functions which are provided by the programming language to give standard functionality
40
What are the benefits of using built-in functions? (3)
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
Method
A function associated with a particular data type
42
Parameter
A variable name declared in the function definition. It is passed a value when the function is called
43
Argument
A value passed to a function when it is called
44
Return value
The result that is returned from a function
45
Variable scope
The amount of the program in which a variable is recognised and can be used
46
Global variable
A variable declared in the main part of the program that can be accessed anywhere in the program
47
Local variable
A variable declared within a function and which can only be accessed inside said function
48
What are the rules when it comes to variable scope? (3)
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
What is the scope of variables used to control loops in Python?
Local to the function the loop is written in
50
What are the three main types of errors?
1. Syntax 2. Logic 3. Runtime
51
Syntax error
An error in the format of program statements
52
Syntax
A set of rules defining how program statements must be written in order for them to be understood by the translator
53
What are some examples of common syntax errors? (4)
1. Mistyping a keyword 2. Missing keywords out from constructs 3. Leaving brackets open 4. Using the incorrect number of parameters
54
Logic error
An error in the algorithm logic that means that it does not work as expected, even though it runs
55
What are some examples of common logic errors? (3)
1. Missing brackets out of mathematical calculations 2. Loops that run the incorrect number of times 3. Initialising variables in the wrong place
56
Runtime error
An unhandled error raised in runtime, which is outside of the control of your program
57
What are some examples of common runtime errors? (4)
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
Error handling
Coding that protects the program from runtime errors by pre-empting possible errors triggered by issues beyond the scope of the program code
59
What is the syntax used for error handling in Python?
try: except:
60
Trace table
A manual way of tracking an algorithm by following the changing values of variables throughout the code
61
IDE
Integrated Development Environment: a programming environment which provides features such as code editing, debugging help and runtime diagnostics
62
How can a programmer check to make sure their code is error-free? (3)
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
Text file
A file that is structured in lines and only contains ASCII characters
64
Comma Separated Value file
A text file with multiple values on each line of text, which are separated by commas
65
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
1. text ← READLINE(filename, lineNo) 2. WRITELINE(filename, lineNo, text) 3*. WHILE NOT eof(filename) ... 4. OPEN filename to read/write 5. CLOSE filename *eof = End Of File
66
What are the steps to read from a text file? (4)
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
What are the steps to write to a text file? (4)
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
What kind of error is caused by an unclosed file?
A runtime error
69
Database
A structured collection of related data
70
State whether the following can be accessed using a text editor: 1. A text file 2. A CSV file 3. A database
1. Yes 2. Yes 3. No
71
State whether the following could be accessed using certain spreadsheet or database programs: 1. A text file 2. A CSV file 3. A database
1. No 2. Yes - each line is a record, and each value between commas a field 3. Yes
72
When would using a text file be a better choice than using a relational database? (4)
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
API
Application Programming Interface: the interface provided by operating systems to help programmers create applications that run on it (e.g. library programs)
74
Library program
The systems software provided by the operating system so that application programmers don't have to rewrite basic functionality
75
What are the benefits of using library programs? (4)
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
Open Source program
A program that is created using free software that allows free access to the source code
77
The Open Source Initiative License states that... (3)
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
Pros and Cons of using Open Source software (2 | 2)
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
Data structure
A temporary structure in main memory which stores related data items together to form a set of data while a program runs
80
Array
A collection of data items of the same data type, grouped under a single identifier
81
2-dimensional array
An array made up of 1-dimensional arrays. Used to add rows
82
What is the syntax used to access nested values within a 2-dimensional array?
array_name[iexp1][iexp2]
83
Examples of sequence data structures include... (4)
1. Arrays 2. Strings 3. Tuples 4. Lists *#3 onwards is Python-specific
84
What are the benefits of using sequence data structures? (3)
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
Subscript OR Index
The numerical reference to a single data item within a sequence data structure
86
What is the syntax used to access values in a sequence data structure?
sequence[iexp]
87
What number does indexing start at in: a. Pseudocode? b. Python?
a. 1 | b. 0
88
Python data structures include... (4)
1. Lists 2. Tuples 3. Dictionaries 4. Classes
89
State the kind of brackets used to denote the following Python data types: 1. Lists 2. Tuples 3. Dictionaries
1. Square brackets 2. Parentheses 3. Curly braces
90
List
A list of values, not necessarily all of the same data type, which is mutable
91
Tuple
Similar to lists, but are immutable
92
Why might someone use a tuple instead of a list? (2)
1. Tuples are faster | 2. They use up less memory space
93
Dictionary
An index of unique keys, where each key is associated with a value
94
Class
A user-defined prototype for a data structure, which can include functions
95
Why might you use a class?
Classes help to enclose functions and their relevant data, aiding data abstraction and readability. This becomes more crucial as a program gets larger
96
State whether the following are inherently ordered: 1. List items 2. Tuple items 3. Dictionary items 4. Class attributes
1. Yes 2. Yes 3. No 4. No
97
Mutable
Describes an object whose value can change
98
Immutable
Describes an object whose value is unchangeable after being created
99
State whether the following are mutable or immutable: 1. Lists 2. Tuples 3. Strings 4. Numbers (Integers and Floats) 5. Dictionaries
1. Mutable 2. Immutable 3. Immutable 4. Immutable 5. Mutable