OCR Exam Reference Language Flashcards
Casting example
str(29)
int(“102”)
float(30)
bool(“False”)
Random number
number = random(1100)
Iteration (for loop) example
for i = 1 to 10 step 1
input item
next i
Iteration (while loop) example
while firstname != “Steven”
firstname = input(“Try again:”)
endwhile
Length of a string example
word = “dictionary”
print(word.length)
String cases example
phrase = “The Cat Sat On The Mat”
print(phrase.lower)
prin(phrase.upper)
ASCII Conversion
ASC(“C”) returns 67
CHR(100) returns “d”
File handling - writing to a (new) file example
newFile(“paint.txt”)
file2 = open(“paint.txt”)
paint = input(“Enter a paint colour:”)
file.writeLine(paint)
file2.close()
Declare arrays
array names[3]
array names = “Ella”, “Sam”, “Ali”