4.1 (every spec covered) Flashcards
(121 cards)
What is an array (1)
an ordered, finite set of elements of a single type.
What is selection (1)
Where the program executes different actions depending on the result of the comparison.
Difference between definite and indefinite iteration (2)
Definite iteration - The number of iterations is known before execution
Indefinite iteration - Number of iterations depends on a logical condition
What is nested selection (1)
Nested selection is when there is more than one expression to be tested
What is nested iteration (1)
iterating over elements of one or more iterable objects within another iteration loop.
What is the symbol for integer division and for real divison (2)
real division - /
integer division - //
What is modulus and what is the symbol for it? (2)
Modulus calculates the remainder from an integer division
Symbol for modulus is %
What is truncation and how is it achieved in python (2)
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 (3)
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 (2)
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 (2)
Concatenation is the joining together of strings.
string_3 = string_1 + string_2
How do we go from: (2)
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 (2)
import random
number = random.randint(range excluded)
What is exception handling (1)
A technique used to catch and manage runtime errors in a program.
What is subroutine (1)
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 (2)
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 (1)
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 (1)
An area of the stack is allocated data to store during a subroutine call, ( return addresses, parameters, local variables)
What is a function (1)
A subroutine consisting of a series of instructions to perform a task
What is recursion (1)
A function that calls itself until a base case is met.
What are attributes and what are methods (2)
Attributes - Characteristics of an object
Methods - Functions that belong to an object
What is a class (2)
Template used to create objects
Describes the shared attributes and methods of the objects to be created.
what is a object (1)
Once instance of a class, representative of a real world object