2.2 Programming Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Variable

A

Name/ label used to identify a memory location used to store a value that can change while the program is running
e.g. age = 12

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

Constant

A

Name/ label used to identify a memory location used to store a value that cannot change while the program is running
e.g. const PI = 3.14

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

Basic programming constructs

A

-sequence
-selection
-iteration

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

Sequence

A

Execution of statements one after the other in order

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

Selection

A

Construct used to make decisions in a program based on the result of a boolean condition
e.g. if else
-case =

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

Iteration

A

Construct used to repeat sections of code - looping
-count controlled iteration: repeats code a defined number of times - for loop
-condition controlled iteration - checks condition each time around the loop and decides whether to repeat the code again or continue the rest of the program - while/ do…until

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

Arithmetic operators

A

Used to carry out basic mathematical operations on numerical values

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

Arithmetic operators - addition, subtraction, multiplication, division, modulus, floor division, exponent (OCR/ Python)

A

+ +
- -
* *
/ /
MOD %
DIV //
^ **

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

Comparison operators

A

Used to evaluate expressions to a boolean True or False condition

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

Comparison operators - equal to, not equal to, less than, less than or equal to, greater than, greater than or equal to

A

==
!=
<
<=
>
>=

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

Boolean operators

A

Allow multiple conditions to be evaluated
AND - both conditions to be true
OR - one or the other or both to be true
NOT - reverses true or false outcome from a condition

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

Data types

A

-integers - whole numbers, + or -
-real (float) numbers - decimals
-boolean variables - true/ false
-character - single item from a character set
-string - collection of characters (word/ sentence)

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

Casting

A

Conversion of one data type to another
str()
int()
float()
bool()

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

String manipulation

A

Allows string to be sliced, concatenated, modified
Slicing - extract individual characters from a string
Concatenation - join strings together

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

String manipulation code

A

.upper()
.lower()
x = len()
x = y[z] - position of character to extract from (z)
x = y [:z] - return characters up to z in string
x = y[-z:] - return characters to right of string
x = y[w:z] - extract from middle of string

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

Basic file handling operations

A

-files must be open before use and closed once operations are completed

To open and read a file:
file = open(“songlist.txt”,”r”)

Contents can be stored in a variable:
content = file.read()

Print the contents:
print(content)

Close the file:
file.close()

To open and write a file: (override existing data)
file=open(“songlist.txt”,”w”)

To add to a file: (append)
file=open(“songlist.txt”,”a”)

17
Q

SQL

A

Structured Query language - language used to access data stored in a database
SELECT - fields to return
FROM - which table data will return from
WHERE - include criteria

SELECT * - return all fields

18
Q

1D array

A

Allows programmer to store multiple items of data under a single identifier
-item can be accessed through a single index number
e.g.
colours[2] - returns third item
colours[1] = “purple” - replace second item with “purple”

19
Q

2D array

A

Allows programmer to store multiple items of data under a single identifier in a table structure and access each element using two index numbers
-read question: is it [row,column] or [column, row]
e.g.
colours[1][2] - returns item at row 1, column 2
colours[3][1] = purple - replace item at row 3 column 1 with “purple”

20
Q

Iterate/ loop through arrays

A

-e.g. 1D array - Calculate total and output result
total = 0
for x in range(0,5):
>total += numbers[x]
print(total)
-e.g. 2D array - reset each colour in array with empty string
for x in range(0,5):
>for y in range(0,3):
»colours[x][y] = “”

21
Q

Subprograms

A

Programs split into multiple sections
-makes code easier to read and maintain
-reduces size of code
-reuse code without copy and pasting

22
Q

Procedures

A

Subprogram that does not return a value to the main program
e.g.
def add(num1,num2)
>total = num1+num2
>print(total)

23
Q

Functions

A

Subprogram that does return a value to the main program
-return keyword must be used when defining a function
e.g. def add(num1,num2):
>total = num1+num2
>return total

-if you call a function, make sure you have a variable ready to store value returned
answer = add(x,y)

24
Q

Random number generation

A

number = random.randint(1,100)