Computational Thinking (IV) - Exam Reference Language Flashcards

You may prefer our related Brainscape-certified 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
Q

Give an example of DO WHILE loop (condition-controlled) iteration using do and until…

A

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
Q

What are the keywords for an IF-THEN-ELSE selection

A

if… then

elseif… then

else

endif

27
Q

Give an example of an IF-THEN-ELSE selection

A

if answer == “Yes” then
print(“correct”)

elseif answer == “No” then
print(“incorrect”)

else
     print(“error”)

endif

28
Q

What are the keywords for a CASE SELECT or SWITCH?

A

switch… :

 case… :

 case… :

 default:

endswitch

29
Q

Give an example of a CASE SELECT or SWITCH

A

switch day :

 case “Saturday” :
      print(“Weekend - Saturday”)

 case “Sunday” :
      print(“Weekend = Sunday”)

 default:
      print(“Weekday”)

endswitch

30
Q

How can a string length be found?

Give an example

A

.length

subject = “Computer Science”)

subject. length
* Gives the value 16

31
Q

How can .substring, .left and .right be used?

A

.substring(x , i)

.left(i)

.right(i)

*x is starting index and i is number of characters; 0 indexed

32
Q

Give an example of .substring, .left and .right

A

subject = ”Computer Science”

subject.substring(3,5)

Returns “puter”

subject.left(4)

Returns “Comp”

subject.right(3)

Returns “nce”

33
Q

What is used for concatenation?

Give an example

A

+

stringA = “Hello”
stringB = “ how are you?”

print(stringA + stringB)

34
Q

What are the keywords for uppercase and lowercase?

Give examples

A

.upper

.lower

subject = “Computer Science”

subject.upper

Gives “COMPUTER SCIENCE”

subject.lower

Gives “computer science”

35
Q

What keywords are used for ASCII conversion?

Give an example from a character to a reference number and vice versa

A

ASC(…)

CHR(…)

ASC(A)

Returns 65 (numerical)

CHR(97)

Returns ‘a’ (character)

36
Q

How can a file be opened?

Give an example

A

.open()

myFile = open(“sample.txt”)

*The file needs to be stored as a variable

37
Q

How can a file be closed?

Give an example

A

.close()

myFile.close()

38
Q

How can a line be read?

Give an example

A

myFile.readLine()

Returns next line in the file

39
Q

How can a line be written?

Give an example

A

.writeLine(…)

myFile.writeLine(“Add new line”)

*The line will be written to the END of the file

40
Q

How can the end of file be identified?

Give an example

A

.endOfFile()

while NOT myFile.endOfFile()

 print(myFile.readLine())

endwhile

41
Q

How can a new file be created?

Give an example

A

newFile()

newFile(“myDocument.txt”)

*Creates a new text file called “myDocument” which would need to be opened using the .open command

42
Q

Give the array declaration keyword and example using [5] colours

A

array colours(…)

array colours[5]

Creates 1D array with 5 elements (index 0 to 4)

43
Q

Give the array declaration keyword and example using colour example, e.g. “Blue”, “Green”, “Red” etc…

A

array colours(…)

array colours = [“Blue”, “Green”, “Red”, “Yellow”, “Purple”]

Arrays can be declared with values assigned

44
Q

Give an example on an array which is 0 indexed and stored as a single data type

A

array gameboard(…,…) = …

array gameboard[8,8]

Creates 2D array with 8 elements (index 0 to 7)

45
Q

Give an example of an assignment array with keywords used

A

names[…] = …

gameboard[…,…] = …

names[3] = “Pye”

gameboard[1,0] = “Timber Hearth”

46
Q

What are the keywords for a procedure

A

procedure name(…)

endprocedure

47
Q

Give an example of a procedure

A

procedure agePass()

 print(“You are old enough to ride”)

endprocedure

48
Q

Give an example of how to call a procedure (called “check”) using the keywords

A

procedure(check)

49
Q

Give an example of calling a procedure called “check”

A

agePass()

print(check)

multiply(check1, check2)

50
Q

What are the keywords for a function?

A

function name(…)

 …

 return …

endfunction

51
Q

Give an example of a function

A

function squared(number)

 squared = number^2

 return squared

endfunction

52
Q

How is the function “check” called?

A

function(check)

53
Q

Give an example of calling a function

A

print(check(4))

newValue = check(4)

Function returns should be stored in a variable if needed for later use in a program

54
Q

What is the keyword for random?

A

random(…,…)

55
Q

Create a random integer between 1 and 6 inclusive

A

myVariable = random(1,6)

56
Q

Create a random real number between -1.0 and 10.0 inclusive

A

myVariable = random(-1.0,10.0)