paper 2 - OCR reference language Flashcards
how do you declare a constant in the OCR reference language?
using the keyword const (e.g. const pi = 3.14
how can variables in the main program can be made global in OCR reference language?
with the keyword global (e.g. global userID = 123)
what would 13MOD5 give?
3
what would 17DIV5 give?
3
give a statement in OCR reference language that will print “Hello” 8 times.
for i=0 to 7
print (“Hello”)
next i
what does the ‘step 2’ command do in for loops in OCR reference language? Explain an example of it being used
it increases the counter (i) by 2 each time. E.g., the program:
for i=0 to 7 step 2
print (“Hello”)
next i
Will print “Hello” 4 times, because the step 2 command increases the counter (i) by 2 each time.
give an example of a DO…UNTIL loop in OCR reference language
do
answer = input(“New answer”)
until answer != “Correct”
which command will return the length of the string in OCR reference language?
stringname.length (e.g. the program
subject = “Computer Science”
print (subject.length)
would return 15)
how would you print a substring in OCR reference language?
stringname. subString (startingPosition, numberOfCharacters)
e. g. when subject = “Computer Science”, subject.substring(3,5) will return “puter” (remember it starts at the 0th character)
when subject = “Computer Science”, what would subject.left(4) return?
“Comp”
when subject = “Computer Science”, what would subject.right(3) return?
“nce”
how would you convert the variable Subject into upper case letters?
Subject.upper
how would you convert the variable Subject into lower case letters?
Subject.lower
in OCR reference language, what command is used to open a file to read from?
open(“filename.txt”)
In OCR reference language, which command would be used to return a line of text from the file myFile?
x = myFile.readLine()