4.1 (every spec covered) Flashcards

(121 cards)

1
Q

What is an array (1)

A

an ​ordered, finite set of elements​ of a ​single type​.

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

What is selection (1)

A

Where the program executes different actions depending on the result of the comparison.

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

Difference between definite and indefinite iteration (2)

A

Definite iteration - The number of iterations is known before execution

Indefinite iteration - Number of iterations depends on a logical condition

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

What is nested selection (1)

A

Nested selection is when there is more than one expression to be tested

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

What is nested iteration (1)

A

iterating over elements of one or more iterable objects within another iteration loop.

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

What is the symbol for integer division and for real divison (2)

A

real division - /

integer division - //

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

What is modulus and what is the symbol for it? (2)

A

Modulus calculates the remainder from an integer division

Symbol for modulus is %

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

What is truncation and how is it achieved in python (2)

A

Truncation is the process of limiting the number of digits after the decimal point.

In order to perform it in python you need to import math library and use the math.trunc(number) function

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

What is rounding and how is it achieved in python (3)

A

Rounding replaces a number with an approximate value using fewer digits.

python has an inbuilt round() function

round(number, nr of dp)

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

How do we get a substring of a larger string (2)

A

Characters and phrases can be extracted from a string based on their position using [] in Python

[:3] Extracts the 0th ,1st and 2nd character from the string.

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

What is concatenation and how is it achieved (2)

A

Concatenation is the joining together of strings.

string_3 = string_1 + string_2

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

How do we go from: (2)

character → character code
* character code → character

A

chr() converts ASCII code to character
ord() does the opposite

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

How do we generate a random number in python (2)

A

import random

number = random.randint(range excluded)

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

What is exception handling (1)

A

A technique used to catch and manage runtime errors in a program.

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

What is subroutine (1)

A

a set of instructions designed to perform a frequently used operation within a program.

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

What are the advantages of using subroutines in programs (2)

A

The same code only has to be written once to be re-used. making it more efficient.

Its also easier to maintain and fix the code

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

What is an interface (2)

A

An interface defines a contract for classes that implement it.

It specifies a set of methods (functions) that the implementing classes must provide.

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

What are local variables (1)

A

Variables that are declared and used in a subroutine, only in existence while the subroutine is being executed.

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

How is a stack frame used in the context of subroutines (1)

A

An area of the stack is allocated data to store during a subroutine call, ( return addresses, parameters, local variables)

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

What is a function (1)

A

A subroutine consisting of a series of instructions to perform a task

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

What is recursion (1)

A

A function that calls itself until a base case is met.

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

What are attributes and what are methods (2)

A

Attributes - Characteristics of an object

Methods - Functions that belong to an object

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

What is a class (2)

A

Template used to create objects

Describes the shared attributes and methods of the objects to be created.

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

what is a object (1)

A

Once instance of a class, representative of a real world object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is instantiation (1)
Creating an instance of a class
26
What is encapsulation (2)
Protection of attributes and methods of an object so they can’t be accessed or altered by other objects. Requires all interaction to be performed through an objects methods
27
What is inheritance and what is the class diagram symbol for it (3)
A new class is created that retains the attributes and methods from the parent class. Symbol is a arrow with a clear tip "is a" relationship
28
What is aggregation and what is the class diagram symbol for it (4)
Is where an object is created that can contain other objects. If original object is deleted composed objects continue to exist weaker form of composition Class diagram symbol - empty diamond arrow
29
What is composition and the class diagram symbol for it (4)
is where an object that is created can be composed of other objects. If the original objects is deleted so are the composed objects. one class contains an instance of another class to reuse its functionality rather than inheriting from it. Class diagram symbol - Filled in diamond arrow
30
Given the following code how would we override the fly method in the bird class in a new penguin class ( 3 lines) Class bird: def fly(self): return "flying"
Class Penguin(bird): def fly(self): return "not flying"
31
What is polymorphism (1)
Where different objects in a class can be processed differently while making use of the same method.
32
What is overriding (2)
way of achieving polymorphism: redefining a method in a subclass that already exists in a superclass
33
What are the three oop design principles (3)
encapsulate what varies * favour composition over inheritance * program to interfaces, not implementation.
34
Elaborate on the phrase "encapsulate what varies" (3)
when designing classes and objects, we should encapsulate the parts of the code that are likely to change. By doing so, we can localize the effects of change, making the code easier to maintain, modify, and extend. Essentially keep the things that change separate from things that stay the same
35
What are the different types of association in OOP? (4)
Inheritance Aggregation Composition Association
36
Elaborate on the point "favor composition over inheritance" (3)
Favoring composition mitigates the risks of the fragile base class problem, leading to more modular, maintainable, and adaptable object-oriented designs. Composition lets you plug and swap components more flexibly
37
Explain the point " Program to interfaces not implementation (2)
Instead of relying on specific implementations of objects, focus on defining interfaces that describe the behaviour or capabilities that objects should have not specific classes.
38
What are abstract methods (2)
A method that is declared but not implemented in a class. It serves as a placeholder for functionality that must be provided by subclasses.
39
What are static methods (1)
Static methods in Python are methods that are bound to the class rather than to an instance of the class.
40
What are virtual methods (1)
Methods that can be overridden ina subclass
41
What is meant by public specifier (1)
Public members are accessible from any part of the program
42
What is meant by protected specifiers and how are they shown in oop (2)
Protected members are accessible within the class itself and by its subclasses _name
43
What is meant by private specifiers and how are they shown in oop (2)
Private members are accessible only within the class in which they are declared. __name
44
What is a paradigm (1)
a fundamental model that guides how we approach and solve problems
45
Why is the OOP paradigm used (4)
Programs are written as a series of modules making them easy to modify and maintain should a fault occur. Data can be hidden within the class that accesses it providing greater system security Through inheritance code can easily be reused saving memory. Classes are only concerned with the data defined within it, so it is unlikely to access other data accidentally.
46
What is instantiation and example: (2)
Creating an instance of a class Dog1 = Dog()
47
How do we alter the name of An instance of a class item named "Item 1" (1)
Item1.name = "new name"
48
How do we change a string to make it all upper case. String1 = "aaa" (1)
String1 = String1.upper()
49
What is a procedure (1)
A procedure is a block of code that performs a specific task and may or may not return a value
50
What are identifiers (1)
Symbolic names used for any variable, function or definition in a computer program
51
What does the DIV operator do (1)
The div operator performs integer division if both operands are integers. It gives the result of the calculation and the remainder 5 DIV 2 = 2R1 ( 2 remainder 1)
52
How do we perform exponentiation (1)
X**n X is multiplied repeatedly n times
53
Difference between functions and procedures (2)
Function always returns a value Procedure may not return a value
54
What is a constructor method and how do we define it in python oop(3):
def __init__(): initialize newly created objects of a class. The __init__ method is called automatically when an object is instantiated
55
What is the role of the self parameter (1)
self parameter in Python refers to the instance of the class itself.
56
Define a class for a dog with a bark method: (3)
class dog: def bark(self): print("bark")
57
Within the class dog i have a bark function How do i make use of the bark function for my object dog1 = dog() (1)
dog1.bark
58
class customer: def__init__(self, name, email) What is missing from the code and why must it be there (2)
self.name = name self.email = email Assigns a name and email for each instance of a class, the self represents whichever instance of the class we are dealing with.
59
what function allows us to add a item to the end of a list (1)
ListName.append("item")
60
If we want the dog class to inherit the methods and attributes of the pet class what words must be added to the code below (1) class dog():
pet must be put as a parameter class dog(pet):
61
what does super() do in python (2)
Reference the super class (class we inherit from) way of specifically inheriting only certain methods from a parent class
62
how do we convert integer to binary in python (1)
using the inbuilt bin() function for example bin(9) returns: 1001
63
How do we convert a number into hexadecimal string (1)
Using the inbuilt hex() function hex(15) output f
64
How do we return the absolute value of a number (1)
abs() abs(-19.345) output 19.345
65
which function can we use to simulate mod division (1)
divmod() Returns: (quotient, remainder) divmod(30,4) (7,2)
66
What function can be used to find the unique identifier of variables (1)
id()
67
how do we find the maximum and minimum values of an iterable variable (2)
max() min()
68
How do we print the reverse of a string (1) named string
reverse_string = string[::-1] a[start:stop
69
round num to 2 dp (1) num = 9.76515
RoundedNumber = round(num,2) uses inbuilt function round()
70
Advantage of static structure (2)
Static - Memory addresses will be allocated at compile time data is fixed and contiguous allowing faster access,
71
advantage of dynamic data structure (2)
Dynamic - memory requirements can change as a program is running , memory is only used when required
72
what are the 3 types of queues (3)
Linear queue Circular queue Priority queue
73
what is the linear queue (1)
Linear queue - FIFO data structure organised as a line of data. Has a start and end pointer
74
what is a circular queue (1)
FIFO data structure where the first and end pointers wrap around the array.
75
what is a priority queue (1)
same as linear except each element in queue has a priority
76
How do we handle exceptions in Python? (1)
Using try and except:
77
What is the difference between a parameter and an argument? (2)
A parameter is a variable in the function definition. An argument is the actual value passed to the function.
78
What are the main programming paradigms? (2)
Procedural Programming (structured approach) Object-Oriented Programming (using classes and objects)
79
What is procedural programming (1)
A programming paradigm based on the concept of procedures (functions) that manipulate data.
80
what are the advantages of procedural programming (3)
good for smaller linear problems easy to follow and debug modular
81
what is meant by contiguous (1)
when data is stored together one element after another
82
what is the difference between lists and arrays (2)
lists - can hold multiple data types, not stored contiguously array - can hold one type of data, stored contiguously, use less memory
83
what is meant by data type (1)
data we use in programs can come in various shapes and sizes these different forms of data are refered to as data types.
84
what is association (1)
"has a " relationship in oop
85
what is meant by modular code (1)
A technique of code design where a solution is broken down into a number of small self-contained and manageable chunks'
86
what are the advantages of writing code in a "modular way" (3)
enables different programmers to work on different parts of the code code is easier to read and debug reduces need for duplicated code
87
what are global variables (1)
a variable that is declared outside of any function or subroutine and is accessible throughout the entire program.
88
In object orientated programming what is the purpose of 'GET' and 'SET' methods? (1)
Allows you to access and change private attributes of an object
89
Why can an interface not declare a constructor method (1)
An interface cannot declare a constructor because all of the code found within it is abstract. You need a concrete implementation of the interface by another class.
90
What does this line of object orientated pseudo-code do? Class teacher(Person) (1)
The new subclass teacher 'inherits' or is derived from the parent/super class person which is placed in brackets
91
why can an interface not have attributes for object state. (1)
An interface cannot have attributes for object state because it simply states what methods need to be implemented, not how they are implemented or what data they may use.
92
What data type should be used to store the value of a 4 digit pin number? and why (2)
Unless numbers are going to be used for arithmetic, they should always be stored as strings. In the case of a 4 digit pin number, if it started with a zero and was stored as an integer, the leading zeros would be lost.
93
what is the base class (2)
the highest class that doesn't inherit from any other classes
94
procedural language'? (1)
any high level language in which program statements can be grouped in self-contained blocks called procedures and functions.
95
What is meant by parameter passing (1)
passing values into a sub-routine when it is called.
96
What does a subroutine interface refer to? (3)
It defines the rules for calling the subroutine, including the number and types of parameters, the return value, and any constraints.
97
What is the fragile base class problem (1)
is a software design issue that occurs when a base class is modified in a way that unintentionally breaks derived (subclass) behavior
98
Disadvantages of static data structures (1)
memory is reserved even when it is not used
99
Disadvnatage of dynamic data structures (1)
memory locations used may be fragmented so they may be slower to access
100
what is meant by object state (1)
the state of an object refers to its data at a given time The values stored in its attributes.
101
what is a pointer (2)
A pointer does not hold a data value itself—it holds the location (address) in memory where that data is stored. Commonly used in low-level languages like C and assembly.
102
what is a record (1)
a collection of related fields ( can be different types)
103
what is an immutable value/variable (1)
a value/variable where its state (value) cannot be modified once it has been created.
104
how do we remove specific values from a string (1)
Using the .strip(function)
105
text = " hello world " cleaned = text.strip() print(cleaned) what will this code output (2)
"hello world" when no value is passed into .strip() it removes removes spaces, tabs, and newlines from both the beginning and end of the string. It does not remove spaces in the middle of the string.
106
text = "!!hello!!" how could we remove the exclamation marks from this variable without creating a new variable as a whole. (2)
text = text.strip("!")
107
how do we remove characters only from the left of a string (1)
.lstrip()
108
how do we remove characters only from the right of a string (1)
.rstrip()
109
what is the symbol for XOR logic gate in python (1)
A ^ B
110
what is the advantage of using constants in python (2)
Prevents accidental changes netter readability
111
how do we find the position of values in a string (1)
.find("x") to find instances of x within a string
112
text = "hello world" (1) index = text.find("world") print(index) what will this code return
6 "world" starts at index 6 in "hello world".
113
text = "hello" print(text.find("z")) what will this code return
Output: -1 when value is not found
114
text = "hello hello" print(text.find("lo", 5)) what will this code return
Output: 9 Starts searching from index 5, so it finds the second "lo".
115
what is the difference between .find() and .index() (1)
.index() works like .find(), but raises an error if the substring is not found.
116
try: print("Before error") x = 1 / 0 # <-- raises ZeroDivisionError print("After error") # <-- never reached except ZeroDivisionError: print("Caught a division-by-zero!") print("Program continues…") what does this code return
Before error Caught a division-by-zero! Program continues… "once 1/0 fails, “After error” is never printed and execution moves straight to the except."
117
what is abstraction (1)
hiding complexities of code and only showing essential features.
118
What is the UML class diagram concept for a public method (1)
+ public method
119
what is the uml class diagram concept for a private variable (1)
- private variable
120
what is the uml class diagram concept for a protected attribute (1)
#protected attribute
121
What is the point of getter and setter methods (1)
to encapsulate access to private attributes