Unit 7 Flashcards

(42 cards)

1
Q

What is a data type

A

The kind of values that can be used in a data item

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

How do you define a constant in OCR exam reference language and why do we do it

A

you write “const” first then define the variable

ie: “const MIN_AGE = 7”

they are typically shown in uppercase

It prevents the code from accidentally being changed by another part of the code
It shows a programmer that the value should stay the same

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

Can a constant ever change its value

A

The value of a constant variable cannot be changed when a program is running

The value of a constant can be changed by a programmer before it is compiled/translated

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

What is casting

A

When you use a function to change the data type of a variable

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

What does bool(x), ASC(x) and CHR(97) do

A

1) converts x into a boolean (eg: “True” into True)
2) converts whatever the character(s) is into ASCII (ie: a would become 97)
3) converts the ascii back to regular character(s) so 97 would be “a”

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

What is concatenation

A

Joining together multiple items of the same data type (ie: string)

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

what does the .substring(x,y) function do to a string

A

it takes a string (ie: London Zoo) and it takes the x position and finds that character, the y position on the string and finds that character and then prints everything in the middle of those

ie: substring(1,4) will take the first “o” and the 2nd “o” (the 1st and 4th position) and it will use everything in between (including this) so the result will be “ondo”

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

What does .left(x) ad .right(x) do

A

.left(x) will take the first x characters out of a string and print them. Opposite for .right() - if the last 4 characters are “goat” from “gogoat” then instead of printing taog it will print goat as its in order

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

What are the purpose of comments

A

Describing the purpose of an algorithm
State the author of the program
Explain what the code does

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

What are the boolean operators

A

AND
OR
NOT

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

When do you use the switch case statement

A

When a selection is to be made from several alternatives (ie: choosing from a menu)

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

What does the library function round() do

A

if the statement is round(x, n) then the function rounds a real (x) to n decimal places

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

How do you use random number generation for python and pseudocode

A

Pseudocode:
die = random(1, 6)
print(die)

Python:
import random
die = random.randint(1, 6)
print(die)

for randomising, all numbers including start and end are inclusive for both languages

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

what is the definition of sequence

A

the statements are executed one by one in the order they are written

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

selection

A

The next statement to be expected depends on whether the condition tested is true or false

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

iteration

A

Repetition of a section of code

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

Describe a for loop

A

Its a fixed loop - the code is repeated a known number of times

When a fixed loop executes, the program counts the number of ties the code has been repeated which is stored in the loop variable

18
Q

How can you work out how many times a for loop will run if you’re given the loop ie: for counter = 0 to 9 and what about python

A

the last number - the first + 1 // the step

9-0+1 = 10
if its from 1 to 9 then it will be 9 times

For python it is just the last - the first as it is exclusive

(THIS WORKS FOR POSITIVE AND SOME NEGATIVES I THINK)

19
Q

What is an array

A

A data structure allowing you to several variables of the same type with one name

20
Q

How do you define an array of constants

A

name = [“…”, “…”, “…“…]

It doesn’t have to be only string

21
Q

What is an advantage of using arrays

A

Instead of making a bunch of different variables, you can make one array to store all of the different values, which can be individually accessed easily otherwise it would be very inconvenient

22
Q

How do you construct a 2D array in pseudocode

A

Student1 1 2 3 4
Student2 4 5 5 1
student3 9 8 9 9

array Total[3]

23
Q

What’s the difference between a function call and function definition

A

definition: used to define the steps within the function

call: Tells the program to branch to the function, execute it and comeback to the next statement in the program

24
Q

What’s the difference between a function and procedure

A

FUNCTION RETURNS A VALUE

PROCEDURE DOES NOT

25
When calling a function, like converter(x,y) what are the parameters
x and y
26
How do you define functions in pseudocode
function (function name)(parameters) ... return... end function
27
What are procedures and their purpose
Another type of subroutine used in SOME programming languages They dont necessarily return a value and may or may not have parameters They are useful for breaking down a program into self contained modules
28
How do you define and call procedures in pseudocode
define procedure GetAge ... call GetAge
29
Why would you use subroutines
useful to break up a large portion of code into self contained chunks each subroutine can be tested so it can work perfectly Many programs can be used work on a large project at a time cutting down development time
30
What is the scope of a variable
The scope of a variable constant procedure or function defines the part of the program in which it is recognised and can be used for example if there are 2 functions with function 1 having variable x y and z and function 2 having l m and o. Outside the functions there is variable an and b. variables a and b are global and can be seen anywhere variables a b and c can only be seen inside function 1 variables l m and o can only be seen inside function 2
31
Local variables
Only exist while the subroutine is being executed Only accessible in the subroutine
32
What is a data structure
a collection of elementary data types
33
What is a record
A data structure consisting of a number of fields which can all be of different types
34
What is a field
A single item of data in a record
35
What is a file
A collection of records
36
With text files the only data type is
string
37
How do you open a file (marks.txt) in python and give the program access to it, ie, letting it read, write and append to a file
markFile = open("marks.txt", "r") = read markFile = open("marks.txt", "w") = write markFile = open("marks.txt", "a") = append
38
How do you read a line from the file (its already been opened/assigned to markFile) and print the output in python
markLine = markFile.readline print(markLine)
39
How do you close a file in python (the files assigned to markFile)
markFile.close
40
How do we split up a file
markFile = open("marks.txt", "r") you want to use the .split() function and as a parameter use the character you want to split the string into, ie: comma
41
What does SQL stand for and what is it used for
Structured query language It is a language which allows you to create query update and delete data to and from databases
42
What is the SQL syntax
SELECT (lists the fields to be displayed) FROM (specify table name) WHERE (List criteria) ie: if theres a table, you SELECT the columns you want to check (or use SELECT * to select all columns) FROM the table name WHERE name.left(1) = "A" with SELECT, not only will it check in these but the result will print out whatever is selected even if you select only one column, you can still make the criteria from other columns as SQL takes into account wherever the FROM is pointing to ie: select the peoples first names and last names from this table where their town is Beckenham