Programming Flashcards
What are the 3 basic programming constructs?
Sequence - the order of instructions
Selection - an instruction is only carried out if a condition is met (if, elif, else)
Iteration - looped section of code
What are the 2 types of iteration?
Definite iteration - count controlled (for)
Indefinite iteration - condition controlled (while, repeat until)
What is nested iteration?
When a loop is included inside another loop
What is nested selection?
When more than one decision needs to be made when carrying out a task
What is nesting?
The process of including one programming construct within another
What is a variable?
A named piece of memory which contains a value that can change.
What is an identifier?
The name of a variable?
What is declaration?
Giving a variable a name or giving a value to a constant
What is assignment?
Giving a variable a value
What is a constant?
A named piece of memory which holds a value that cannot change.
What is scope?
Refers to where a variable, constant, function or procedure can be used - it can be either local (within a subroutine) or global (the whole program)
What are the 5 data types?
Integer - number
String - text
Boolean - true/false
Character - a singular letter/number
Float/ float - decimal
What is casting?
The process of changing the data type of a variable e.g. int(‘54’) returns 54
What are the arithmetic operators?
*
/
DIV (//)
MOD (%)
What are the relational operators?
Used for assignment and comparison:
= - assignment
== - equivalence
< - less than
<= - less than or equal to
> - greater than
>= greater than or equal to
!= - not equal to
What are the Boolean operators?
AND
OR
NOT
What is an array?
A data structure that holds similar, or related data (a list). Each element has a position (index) within the array and holds a value. They must all be of the same data type.
How is an array declared?
A programmer gives it 2 properties:
An identifier and
A size
How is a 2d array declared?
With an identifier and 2 values - a row and a column
How can you determine the length of a string?
len()
How can you determine the position of a character in a string?
string[0]
where string = the variable and 0 = the position
What is a substring?
A set of characters that exists inside of a string.
How can a random number be generated?
import random
random.randint(range)
What is a subroutine?
A smaller piece of named code that exists within a larger program - its purpose is to perform a specific task.
(using these is sometimes called structured programming!)