Computational Thinking (IV) - Exam Reference Language Flashcards
What does the comparison operator == mean?
Equal to
What does the comparison operator != mean?
Not equal to
What does the comparison operator < mean?
Less than
What does the comparison operator <= mean?
Less than or equal to
What does the comparison operator > mean?
Greater than
What does the comparison operator >= mean?
Greater than or equal to
What is the arithmetic operator for addition?
+
What is the arithmetic operator for subtraction?
-
What is the arithmetic operator for multiplication?
*
What is the arithmetic operator for division?
/
What is the arithmetic operator for exponent?
What is the arithmetic operator for modulus?
MOD
What is the arithmetic operator for quotient?
DIV
What are the three Boolean operators?
AND (logical AND)
OR (logical OR)
NOT (logical NOT)
What is used for a comment?
Give an example
//
//Square a number squared = number^2
//Print the result print(squared)
What is the symbol for the assignment of a variable?
Give an example
=
name = “Bob”
What is the keyword for a constant?
Give an example
const
const temperaturelimit = 39.8
What is the keyword for a global variable?
Give an example
global
global schoolID = “Noadswood”
How can an input be given?
input(…)
How can an output be given?
print(…)
What casting keywords are used?
str()
int(“3”)
float(“4.52”)
real(“4.52”)
bool(“True”)
Give an example of the FOR loop (count-controlled) iteration using for… to… next…
for i = 0 to 9
print(“Loop”)
next I
This will print the word “Loop” ten times
Give an example of the FOR loop (count-controlled) iteration using for… to… step… next…
for i = 2 to step 2
print(i)
next i
This will print the even numbers from 2 to 10 (inclusive)
Give an example of WHILE loop (condition-controlled) iteration using while… and endwhile
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
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
What are the keywords for an IF-THEN-ELSE selection
if… then
elseif… then
else
endif
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
What are the keywords for a CASE SELECT or SWITCH?
switch… :
case… : case… : default:
endswitch
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
How can a string length be found?
Give an example
.length
subject = “Computer Science”)
subject. length
* Gives the value 16
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
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”
What is used for concatenation?
Give an example
+
stringA = “Hello” stringB = “ how are you?”
print(stringA + stringB)
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”
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)
How can a file be opened?
Give an example
.open()
myFile = open(“sample.txt”)
*The file needs to be stored as a variable
How can a file be closed?
Give an example
.close()
myFile.close()
How can a line be read?
Give an example
myFile.readLine()
Returns next line in the file
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
How can the end of file be identified?
Give an example
.endOfFile()
while NOT myFile.endOfFile()
print(myFile.readLine())
endwhile
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
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)
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
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)
Give an example of an assignment array with keywords used
names[…] = …
gameboard[…,…] = …
names[3] = “Pye”
gameboard[1,0] = “Timber Hearth”
What are the keywords for a procedure
procedure name(…)
endprocedure
Give an example of a procedure
procedure agePass()
print(“You are old enough to ride”)
endprocedure
Give an example of how to call a procedure (called “check”) using the keywords
procedure(check)
Give an example of calling a procedure called “check”
agePass()
print(check)
multiply(check1, check2)
What are the keywords for a function?
function name(…)
… return …
endfunction
Give an example of a function
function squared(number)
squared = number^2 return squared
endfunction
How is the function “check” called?
function(check)
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
What is the keyword for random?
random(…,…)
Create a random integer between 1 and 6 inclusive
myVariable = random(1,6)
Create a random real number between -1.0 and 10.0 inclusive
myVariable = random(-1.0,10.0)