Logic Points 0 / 40
Coder Rank String Concatenator

Topic 2.2.1: Programming Fundamentals

Variables, Operators, Debugging & Control Flow.

1 [2 Marks]
a = "50" b = "2" c = a + b print(c)
(a) State the output.
(b) Explain why it is not 52.
Hint: Look at the quotes around the numbers. Are they Integers or Strings?
✅ Mark Scheme

(a) 502

(b) The variables are Strings, so the + operator performs concatenation (joining) instead of addition.

Score:
2 [3 Marks]
Calculate the value of result:
  • 17 MOD 3
  • 17 DIV 3 (or 17 // 3)
  • 2 ^ 3 (or 2 ** 3)
MOD = Remainder. DIV = Whole number division. ^ = Power.
✅ Mark Scheme
  • MOD: 2 (Remainder of 17 / 3)
  • DIV: 5 (17 / 3 = 5.66..., ignore decimal)
  • Power: 8 (2 * 2 * 2)
Score:
3 [3 Marks]
_____________ WIDTH = 10 # This value should not change length = ____________(input("Enter the length: ")) area = length * WIDTH print("The area is: " + ____________(area))
Fill in the missing keywords/functions.
✅ Mark Scheme
  1. CONSTANT (or CONST)
  2. int (or float) - Cast input to number
  3. str (or String) - Cast number to string for printing
Score:
4 [4 Marks]
(a) Define 'Variable'.
(b) Why use a Constant for VAT (20%) instead of a variable?
✅ Mark Scheme

(a) A named memory location used to store data that can change while the program is running.

(b) Prevents accidental changes to the value / Makes code easier to update (change in one place).

Score:
5 [3 Marks]
01 name = input("Enter name") 02 age = input("Enter age") 03 nextYear = age + 1 04 Print("Next year you will be " + nextYear)
Identify and fix 3 errors.
Hint 1: Can you do math on a String input?
Hint 2: Is 'Print' the same as 'print'?
Hint 3: Can you join a String and an Integer directly?
✅ Mark Scheme
  • Line 02: int(input(...)) - Must cast input to integer.
  • Line 04: print(...) - Lowercase 'p'.
  • Line 04: ... + str(nextYear) - Cast integer back to string for concatenation.
Score:
6 [4 Marks]
GLOBAL score = 0 function updateScore(points) currentLevel = 1 score = score + points return score endfunction print(currentLevel)
(a) Why does print(currentLevel) cause an error?
(b) Give one disadvantage of Global variables.
✅ Mark Scheme

(a) currentLevel is a Local variable. It only exists inside the function.

(b) Harder to debug (track changes) / Waste memory (stay in memory throughout program).

Score:
7 [5 Marks]
word = "CODE" count = 0 x = len(word) WHILE x > 1 x = x - 1 count = count + x print(x) ENDWHILE print(count)
Trace the variables. What is the final output?

Trace Table:

xcountOutput
✅ Mark Scheme

Loop 1: x=3, count=3

Loop 2: x=2, count=5 (3+2)

Loop 3: x=1, count=6 (5+1)

Loop ends (x is not > 1)

Final Output: 6

Score:
8 [4 Marks]
(a) Define a Record for a Player with: Nickname (Str), Score (Int), IsActive (Bool).
(b) Update player1's Score to 500.
✅ Mark Scheme
RECORD Player
    Nickname : String
    Score : Integer
    IsActive : Boolean
END RECORD

(b) player1.Score = 500

Score:
9 [5 Marks]
score = int(input("Enter score")) if score > 80: print("Distinction") if score > 60 and score <= 80: print("Merit") if score <= 60: print("Pass")
(a) Rewrite using elif / else.
(b) Why is this more efficient?
✅ Mark Scheme
if score > 80:
    print("Distinction")
elif score > 60:
    print("Merit")
else:
    print("Pass")

(b) Once a condition is met, the processor skips the rest. The original code checked ALL statements.

Score:
10 [6 Marks]
Write a Currency Converter program:
  • Const RATE = 1.25
  • Input GBP (allow decimals)
  • If GBP > 0, calc USD and output.
  • Else output "Invalid".
✅ Mark Scheme
CONST RATE = 1.25
gbp = float(input("Enter GBP: "))
if gbp > 0:
    usd = gbp * RATE
    print(usd)
else:
    print("Invalid amount")
Score: