Arithmetic, relational and Boolean operators. String functions: length, substring, upper, lower, charAt. Core Paper 1 skills.
| Operator | Meaning / example |
|---|---|
| + - * / | |
| MOD | |
| DIV | |
| ^ or ** | |
| Precedence (BIDMAS) |
| Operator | Meaning |
|---|---|
| == / != | |
| < / > | |
| <= / >= | |
| Usage | |
| Example |
| Operator | Meaning / example |
|---|---|
| AND | |
| OR | |
| NOT | |
| Combined example | |
| Truth table |
| Operation | Meaning / example |
|---|---|
| LEN(str) | |
| SUBSTRING(str, start, length) | |
| UPPER(str) | |
| LOWER(str) | |
| str[i] | |
| String concatenation (+) |
name = "Ander"
PRINT LEN(name) // Output: 5
PRINT SUBSTRING(name, 0, 3) // Output: "And"
PRINT UPPER(name) // Output: "ANDER"
PRINT name[0] // Output: "A"
// Checking first character
IF UPPER(name[0]) == "A" THEN
PRINT "Name starts with A"
END IF
// String concatenation
greeting = "Hello, " + name + "!"
PRINT greeting // Output: "Hello, Ander!"// MOD: remainder
PRINT 10 MOD 3 // Output: 1
PRINT 8 MOD 2 // Output: 0 (so 8 is even)
// DIV: integer division
PRINT 17 DIV 5 // Output: 3
PRINT 17 MOD 5 // Output: 2 (17 = 3*5 + 2)
// Test if number is even
IF num MOD 2 == 0 THEN
PRINT "Even"
ELSE
PRINT "Odd"
END IFWhat is the result of 17 MOD 5?
What does LEN("Computing") return?
A variable word is assigned the value "Python". Write pseudocode to: (a) print the first 3 characters, (b) print the string in uppercase, (c) print the last character. (3 marks)
Write pseudocode for a program that: asks the user for a number, then prints "Fizz" if divisible by 3, "Buzz" if divisible by 5, "FizzBuzz" if divisible by both, otherwise prints the number. (4 marks)
What is the result of: (5 > 3) AND (10 < 8)?