click below
click below
Normal Size Small Size show me how
CRITICAL POINTS
| Question | Answer |
|---|---|
| Subroutines | a named sequence of instructions that can be reused in other or the same programs. They are called procedures or functions. They save time. |
| Opcode | instruction |
| Operand | data being acted on |
| Metadata | data about data |
| Variable declaration | the point at which a variable is created, In most language, the data type is declared too |
| Initialised | when a variable is assigned to its first value |
| name.upper() (python) | turns string to upper case |
| name.lower() (python) | turns string to lower case |
| name.isupper() (python) | checks if string is in uppercase |
| name.islower() (python) | checks if string is in lowercase |
| ord(‘A’) (python) | returns ascii value (ASC() in pseudocode) |
| chr(65) (python) | returns character at that ascii value (CHR() in pseudocode) |
| Intractable problems | no known efficient algorithm to solve them |
| Boolean Precedence | NOT - highest priority AND - middle priority OR - lowest priority This is somewhat like BODMAS |
| Computational Thinking | a set of problem-solving methods that express problems and solutions in ways that a computer could execute, it can: - Understood - Formally represented and solved |
| Algorithmic Thinking Stages | 1. Understood the problem 2. Formulate the problem 3. Design an algorithm 4. Implement the algorithm 5. Run the code and solve the original problem |
| Induction (thinking logically) | A hypotheses (idea) is proposed based on observations When developing for a stakeholder, existing programs will be observed |
| Deduction (thinking logically) | Uses underlying rules to determine how a system should work More for mathematical/scientific problems where known rules can be applied |
| OCR ERL | pseudocde used in exams |
| Variables (OCR ERL) | Identifier = value Global identifier = value |
| Casting (OCR ERL) | str() int() float() |
| Output (OCR ERL) | print() |
| Input (OCR ERL) | input() |
| Iteration - count controlled (OCR ERL) | For i = 0 to 7 print(“Hello”) Next i |
| Iteration - condition controlled (while) (OCR ERL) | (may never run at all) While answer != “Computer” Answer = input(“”) Endwhile |
| Iteration - condition controlled (do until) (OCR ERL) | (always runs at least once) Do Answer = input(“) Until answer == “Computer” |
| Comparison operators (OCR ERL) | == != < > <= >= |
| Arithmetic operators (OCR ERL) | + - * / MOD - returns remainder of division DIV - returns whole part of division (always rounds down) ^ |
| Logical operators (OCR ERL) | AND OR NOT |
| String handling (OCR ERL) | Get the length: (includes whitespace) Stringname.length Get a substring: (indexing starts at 0) stringname.substring(starting position, no. of characters) |
| Subroutines (function) (OCR ERL) | Function triple(number) Return number * 3 Endfunction |
| Subroutines (procedure) (OCR ERL) | Procedure greeting(name) print(“Hello” + name) Endprocedure |
| Subroutines (pass by value/reference) (OCR ERL) | Procedure name(x:byVal, y:byRef) X is passed by value Y is passed by reference |
| Arrays (OCR ERL) | Array names[3] Names[0] = “A” Names[1] = “B” Names[2] = “C” Print(names[2]) |
| 2D array (OCR ERL) | Array board[8,8] Board[0,0] = “Rook” |
| Selection (if/else) (OCR ERL) | If entry == “a” then print() Elseif entry == “b” then print() Else print() Endif |
| Selection (switch/case) (OCR ERL) | Switch entry: Case ”A”: print() Case “B”: print() Default: print() Endswitch |
| Files (Make x the first line of sample.txt) (OCR ERL) | myFile = openRead(“sample.txt”) X = myFile.readLine() myFile.close() |
| Files (End of file) (OCR ERL) | endofFile() |
| Files (Print out contents) (OCR ERL) | myFile = openRead(“sample.txt”) While NOT myFile.endofFile() print(myFile.readLine()) Endwhile myFile.close() |
| Files (Hello world is made the contents of sample.txt (any previous contents are overwritten)) (OCR ERL) | myFile = openwrite(“sample.txt”) myFile.writeLine(“Hello world”) myFile.close() |
| Comments (OCR ERL) | Denoted by // //this is a comment Can be after some code or on a new line |
| Python file handling (opens a file for reading) | f = open(“filename”, “r”) |
| Python file handling (returns a line of code) | f.readline() (add .strip() at end to get rid of return character) |
| Python file handling (closes file) | f.close() |
| Python file handling (to open file to ‘append/add’) | f = open(“filename”, “a”) |
| Python file handling (writes a new line, and also reuters) | f.write(variable+’\n’) (\n = return button) |
| Python file handling (opens a new file/overwrites an existing file (open for writing)) | f = open(“filename”, “w”) |