2.2 - coding techniques Flashcards

1
Q

how do you ask a user to input something

A

variable = input(“text “)

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

what is it called to change the type of a variable

A

casting

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

what are the 4 main types of variable

A

str - (string) any characters
int - (integer) whole number
float - (floating point) decimals
bool - (boolean) T/F

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

how do you change the type of a variable

A

variable2 = int(variable1)

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

what is modulus (MOD)

A

the remainder of dividing two numbers (%)

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

what is the quotient (DIV)

A

the exact number of times something divides into something else (//)

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

how do you code an exponent

A

**

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

how do you multiply, divide, add or subtract variables

A

*, /, +, -

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

what is a string

A

a set of characters that can include letters, numbers, spaces and special characters

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

what is concatenation

A

adding two strings together (“variable1” + “variable2”)

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

what is string traversal

A

locating or making changes to only a certain character or characters rather than the whole string

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

how do you change case

A

variable.upper or variable.lower

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

how do you find the length of a string

A

len(variable)

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

how do you create a substring

A

variable2 = variable1[start:end]

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

what are the six comparisons you can do with a number

A

==, !=, <, >, <=, >=

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

what is selection

A

using if, elif and else

17
Q

what is a subprogram (function/procedure)

A

a piece of code with an identifier that can be called at any point in the code (function has return, procedure doesnt)

18
Q

how do you code a procedure vs a function

A

def procedurename():
code

procedurename()

def functionname():
code
return variable1

variable2 = functionname()

19
Q

what are the two types of loops and their function

A

While loop - loops as long as a condition is met
For loop - loops a certain number of times

20
Q

how do you program a while loop

A

while variable == x:
code

21
Q

how do you program a for loop

A

for x in variable_list:
code

or

for x in range(1,9)
code

22
Q

how do you stop a loop

23
Q

what is an array

A

a list of data under an identifier

24
Q

what 2 things do you declare when making an array

A

size, identifier

25
what is a database
a store of organised data that you can access (file)
26
what is an attribute (sql)
a single item in a database
27
what is a record (sql)
multiple items in a database grouped together, multiple records make up a file
28
what does * represent in sql
all
29
how do you write an sql query
SELECT * from database WHERE attribute = ""
30
what are the two modes of file operation
read and write
31
what are the three lines of code to open a file, read a line then close the file
file = openRead("file_name") variable = file.readline() file.close
32
how do you write from an array to a text file
file.writeline(array[0])
33
how do you check if you have got to the end of a text file
file.endOfFile