4.1 Fundamentals of Programming Flashcards
What is an array
an ordered, finite set of elements of a single type.
What is selection
Where the program executes different actions depending on the result of the comparison.
Difference between definite and indefinite iteration
Definite iteration - The number of iterations is known before execution
Indefinite iteration - Number of iterations depends on a logical condition
What is nested selection
Nested selection is when there is more than one expression to be tested
What is nested iteration
iterating over elements of one or more iterable objects within another iteration loop.
What is the symbol for integer division and for real divison
real division - /
integer division - //
What is modulus and what is the symbol for it?
Modulus calculates the remainder from an integer division
Symbol for modulus is %
What is truncation and how is it achieved in python
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
What is rounding and how is it achieved in python
Rounding replaces a number with an approximate value using fewer digits.
python has an inbuilt round() function
round(number, nr of dp)
How do we get a substring of a larger string
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.
What is concatenation and how is it achieved
Concatenation is the joining together of strings.
string_3 = string_1 + string_2
How do we go from:
character → character code
* character code → character
chr() converts ASCII code to character
ord() does the opposite
How do we generate a random number in python
import random
number =
random.randint(range excluded)
What is exception handling
Techniques used by the programmer to deal with error conditions.
What is subroutine and what are its uses
a set of instructions designed to perform a frequently used operation within a program.
What are the advantages of using subroutines in programs (2)
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
What is an interface
An interface defines a contract for classes that implement it. It specifies a set of methods (functions) that the implementing classes must provide.
What are local variables
Variables that are declared and used in a subroutine, only in existence while the subroutine is being executed.
How is a stack frame used in the context of subroutines
An area of the stack is allocated data to store during a subroutine call, ( return addresses, parameters, local variables)
What is a function
A subroutine consisting of a series of instructions to perform a task
What is recursion
Where a suboroutine is defined in terms of itself.
What are attributes and what are methods
Attributes - Characteristics of an object
Methods - Functions that belong to an object
What is a class
Template used to create objects
Describes the shared attributes and methods of the objects to be created.
what is a object
Once instance of a class, representative of a real world object
What is instantiation
Creating an instance of a class
What is encapsulation
Protection of attributes and methods of an object so they can’t be accessed or altered by other objects
What is inheritance and what is the class diagram symbol for it
A new class is created that retains the attributes and methods from the parent class.
Symbol is a arrow with a clear tip
What is aggregation and what is the class diagram symbol for it
Is where an object is created that can contain other objects.
If original object is deleted composed objects continue to exist
Class diagram symbol - empty diamond arrow
What is composition and the class diagram symbol for it
is where an object that is created can be composed of other objects.
If the original objects is deleted so are the composed objects.
Class diagram symbol - Filled in diamond arrow
What is polymorphism
Where different objects in a class can be processed differently
while making use of the same method.