Computational Thinking (IV) - Exam Reference Language Flashcards

1
Q

What does the comparison operator == mean?

A

Equal to

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

What does the comparison operator != mean?

A

Not equal to

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

What does the comparison operator < mean?

A

Less than

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

What does the comparison operator <= mean?

A

Less than or equal to

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

What does the comparison operator > mean?

A

Greater than

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

What does the comparison operator >= mean?

A

Greater than or equal to

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

What is the arithmetic operator for addition?

A

+

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

What is the arithmetic operator for subtraction?

A

-

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

What is the arithmetic operator for multiplication?

A

*

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

What is the arithmetic operator for division?

A

/

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

What is the arithmetic operator for exponent?

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

What is the arithmetic operator for modulus?

A

MOD

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

What is the arithmetic operator for quotient?

A

DIV

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

What are the three Boolean operators?

A

AND (logical AND)

OR (logical OR)

NOT (logical NOT)

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

What is used for a comment?

Give an example

A

//

//Square a number
squared = number^2
//Print the result
print(squared)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the symbol for the assignment of a variable?

Give an example

A

=

name = “Bob”

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

What is the keyword for a constant?

Give an example

A

const

const temperaturelimit = 39.8

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

What is the keyword for a global variable?

Give an example

A

global

global schoolID = “Noadswood”

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

How can an input be given?

A

input(…)

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

How can an output be given?

A

print(…)

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

What casting keywords are used?

A

str()

int(“3”)

float(“4.52”)

real(“4.52”)

bool(“True”)

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

Give an example of the FOR loop (count-controlled) iteration using for… to… next…

A

for i = 0 to 9

 print(“Loop”)

next I

This will print the word “Loop” ten times

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

Give an example of the FOR loop (count-controlled) iteration using for… to… step… next…

A

for i = 2 to step 2

 print(i)

next i

This will print the even numbers from 2 to 10 (inclusive)

24
Q

Give an example of WHILE loop (condition-controlled) iteration using while… and endwhile

A

while answer != “correct”

 answer = input(“new answer required”)

endwhile

Loop until the user inputs “correct” with a check condition carried out before entering the loop

25
Give an example of DO WHILE loop (condition-controlled) iteration using do and until…
do answer = input(“new answer required”) until answer == “correct” Loop until the user inputs “correct” with a check condition carried out after each loop
26
What are the keywords for an IF-THEN-ELSE selection
if… then elseif… then else endif
27
Give an example of an IF-THEN-ELSE selection
if answer == “Yes” then print(“correct”) elseif answer == “No” then print(“incorrect”) ``` else print(“error”) ``` endif
28
What are the keywords for a CASE SELECT or SWITCH?
switch… : case… : case… : default: endswitch
29
Give an example of a CASE SELECT or SWITCH
switch day : case “Saturday” : print(“Weekend - Saturday”) case “Sunday” : print(“Weekend = Sunday”) default: print(“Weekday”) endswitch
30
How can a string length be found? Give an example
.length subject = “Computer Science”) subject. length * Gives the value 16
31
How can .substring, .left and .right be used?
.substring(x , i) .left(i) .right(i) *x is starting index and i is number of characters; 0 indexed
32
Give an example of .substring, .left and .right
subject = ”Computer Science” subject.substring(3,5) Returns “puter” subject.left(4) Returns “Comp” subject.right(3) Returns “nce”
33
What is used for concatenation? Give an example
+ ``` stringA = “Hello” stringB = “ how are you?” ``` print(stringA + stringB)
34
What are the keywords for uppercase and lowercase? Give examples
.upper .lower subject = “Computer Science” subject.upper Gives “COMPUTER SCIENCE” subject.lower Gives “computer science”
35
What keywords are used for ASCII conversion? Give an example from a character to a reference number and vice versa
ASC(…) CHR(…) ASC(A) Returns 65 (numerical) CHR(97) Returns ‘a’ (character)
36
How can a file be opened? Give an example
.open() myFile = open(“sample.txt”) *The file needs to be stored as a variable
37
How can a file be closed? Give an example
.close() myFile.close()
38
How can a line be read? Give an example
myFile.readLine() Returns next line in the file
39
How can a line be written? Give an example
.writeLine(…) myFile.writeLine(“Add new line”) *The line will be written to the END of the file
40
How can the end of file be identified? Give an example
.endOfFile() while NOT myFile.endOfFile() print(myFile.readLine()) endwhile
41
How can a new file be created? Give an example
newFile() newFile(“myDocument.txt”) *Creates a new text file called “myDocument” which would need to be opened using the .open command
42
Give the array declaration keyword and example using [5] colours
array colours(…) array colours[5] Creates 1D array with 5 elements (index 0 to 4)
43
Give the array declaration keyword and example using colour example, e.g. “Blue”, “Green”, “Red” etc…
array colours(…) array colours = [“Blue”, “Green”, “Red”, “Yellow”, “Purple”] Arrays can be declared with values assigned
44
Give an example on an array which is 0 indexed and stored as a single data type
array gameboard(…,…) = … array gameboard[8,8] Creates 2D array with 8 elements (index 0 to 7)
45
Give an example of an assignment array with keywords used
names[…] = … gameboard[…,…] = … names[3] = “Pye” gameboard[1,0] = “Timber Hearth”
46
What are the keywords for a procedure
procedure name(…) endprocedure
47
Give an example of a procedure
procedure agePass() print(“You are old enough to ride”) endprocedure
48
Give an example of how to call a procedure (called “check”) using the keywords
procedure(check)
49
Give an example of calling a procedure called “check”
agePass() print(check) multiply(check1, check2)
50
What are the keywords for a function?
function name(…) … return … endfunction
51
Give an example of a function
function squared(number) squared = number^2 return squared endfunction
52
How is the function “check” called?
function(check)
53
Give an example of calling a function
print(check(4)) newValue = check(4) Function returns should be stored in a variable if needed for later use in a program
54
What is the keyword for random?
random(…,…)
55
Create a random integer between 1 and 6 inclusive
myVariable = random(1,6)
56
Create a random real number between -1.0 and 10.0 inclusive
myVariable = random(-1.0,10.0)