Variable · Constant · Integer · Real · Boolean · Character · String · Casting · Operators
input() always returns a String in Pythonname ← valuename = valueplayerScore) or underscore (player_score). Avoid single letters unless writing a loop counter.score ← score + 10 reads the current value of score, adds 10, and puts the result back into score.TAX_RATE is clearer than a bare 0.2 scattered through the programconst keywordconst keyword. In exam pseudocode, always write const.age = 16 score = -5 count = 0price = 4.99 temp = 36.7game_over = False is_valid = Truegrade = 'A' key = '?'name = "Alice" msg = """42" is not the same as the integer 42 — you must cast to use it in arithmetic.input() always returns a String — even when the user types a number. You must cast to Integer or Real before doing arithmetic, or Python will throw a TypeError at runtime.int(x)float(x)str(x)bool(x)17 DIV 5 → 3 (how many times it fits)17 MOD 5 → 2 (the remainder)MOD → Python %DIV → Python //^ → Python **
IF conditions and WHILE loops.== checks equality; ← (ERL) or = (Python) is assignment. Never use a single = inside an IF condition.AND
True AND True → TrueTrue AND False → FalseOR
True OR False → TrueFalse OR False → FalseNOT
NOT True → FalseNOT False → True(A AND B) OR C is different from A AND (B OR C). When in doubt, bracket it.variable ← expressionvariable = expressionstr() first — otherwise you get a TypeError.age = input("Enter age: "). Explain why casting is needed before calculating how many years until retirement age of 65.input() always returns a String [1] — a String cannot be used in arithmetic (subtracted from 65), so it must be cast to an Integer using int() first [1]
num, then output the square of num. Use the correct assignment operator and exponentiation operator for OCR ERL.print(num * num) for the third mark.num = ... instead of num ← ... (wrong assignment operator for ERL)** instead of ^ (Python operator, not ERL)int() cast around input()| Operation | OCR ERL | Python |
|---|---|---|
| Exponentiation | ^ | ** |
| Integer division | DIV | // |
| Modulus | MOD | % |
| Assignment | ← | = |
| Target type | ERL function | Python |
|---|---|---|
| Integer | int(x) | int(x) |
| Real | float(x) | float(x) |
| String | str(x) | str(x) |
← is ERL only; = is Python only.x = 5 in OCR ERL pseudocode — this is Python syntax, not ERLx ← 5age = input("Age: ") then doing arithmetic — causes a TypeError at runtimeage = int(input("Age: "))10 MOD 3 = 3 — MOD gives the remainder, not the quotient10 MOD 3 = 1 (remainder) | 10 DIV 3 = 3 (quotient)2 ** 8 in OCR ERL pseudocode, or 10 % 3 instead of 10 MOD 3^ MOD DIV | Python: ** % //x ← 5); constants store fixed values (const MAX ← 10) and use the const keyword in OCR ERLint(), float(), str(); input() always returns a String — always cast before arithmetic+ − * / MOD DIV ^ · Comparison: == != < <= > >= · Boolean: AND OR NOT←, power with ^, remainder with MOD · Python: assign with =, power with **, remainder with %Get the full resource pack at CSZone.co.uk