Construct Points 0 / 40
Construct Rank Sequential Thinker

Topic 2.2.3: Programming Constructs

Selection, Iteration, Logic & Loops.

1 [2 Marks]
password = input("Enter password: ") length = len(password) IF length < 5: print("Too short") length <= 10: print("Acceptable") : print("Too long")
Fill in the blanks to complete the password validation logic.
✅ Mark Scheme
  • 1. elif (or else if)
  • 2. else
Score:
2 [4 Marks]
(a) Rewrite a switch statement (Choice A=Add, S=Subtract, Other=Invalid) using if/elif/else.
(b) Benefit of Switch over IF?
✅ Mark Scheme
if choice == "A":
    print("Add")
elif choice == "S":
    print("Subtract")
else:
    print("Invalid")

(b) Cleaner code / Easier to read / Optimised by compiler.

Score:
3 [2 Marks]
x = 10 if x > 5: x = x + 5 if x > 12: x = x - 2 print(x)
(a) Final output?
(b) Output if second IF was ELIF?
✅ Mark Scheme

(a) 13 (10->15->13)

(b) 15 (Second incorrect condition skipped because first was true)

Score:
4 [4 Marks]
Identify the Loop Type (For vs While):
(a) Run around track 5 times.
(b) Wait until 'Restart' is pressed.
✅ Mark Scheme

(a) For Loop: Count-Controlled. We know exact iterations (5).

(b) While Loop: Condition-Controlled. Unknown iterations (depends on user).

Score:
5 [2 Marks]
num = 1 while num <= 5: print(num) # End of loop
(a) Why is this infinite?
(b) How to fix it?
✅ Mark Scheme

(a) num is never changed, so num <= 5 is ALWAYS valid.

(b) Add num = num + 1 inside loop.

Score:
6 [3 Marks]
Student code: for i in range(8): print(i)
(a) Actual Output?
(b) Rewrite to output Even numbers: 0, 2, 4, 6, 8.
✅ Mark Scheme

(a) 0, 1, 2, 3, 4, 5, 6, 7 (stops before 8)

(b) for i in range(0, 9, 2): (or range(0, 10, 2))

Score:
7 [5 Marks]
total = 0 FOR i = 1 TO 3 FOR j = 1 TO 2 total = total + i NEXT j NEXT i print(total)
Trace the loop. What is the value of total printed?

Trace Table:

ijtotalOutput
✅ Mark Scheme

i=1, j=1..2 (Total +1+1 = 2)

i=2, j=1..2 (Total +2+2 = 6)

i=3, j=1..2 (Total +3+3 = 12)

Final Output: 12

Score:
8 [4 Marks]
x = 10 WHILE x > 0 print(x) x = x - 3 ENDWHILE print("Blastoff")
Trace output sequence.
✅ Mark Scheme

10 (x becomes 7)

7 (x becomes 4)

4 (x becomes 1)

1 (x becomes -2)

Blastoff

Score:
9 [4 Marks]
valid = False choice = int(input("Enter choice")) if choice == 1: valid = True if choice == 2: valid = True if choice == 3: valid = True if valid == False: print("Error")
Rewrite efficiently without valid flag. Use OR/AND and ELSE.
✅ Mark Scheme
if choice >= 1 and choice <= 3:
    # Do nothing or process choice
    pass 
else:
    print("Error")

Also accept: if choice == 1 or choice == 2 or choice == 3:

Score:
10 [6 Marks]
Write a program:
  • Input count of students.
  • Loop that many times to ask for score.
  • Validate score >= 0 (else output invalid).
  • Calculate and print average.
✅ Mark Scheme
count = int(input("Students: "))
total = 0
for i in range(count):
    score = int(input("Score: "))
    if score < 0:
        print("Invalid")
    else:
        total = total + score
print(total / count)
Score:
11 [3 Marks]
Write a While Loop to guess a secret number (e.g., 7). Keep asking until correct. Print "Found it!".
✅ Mark Scheme
guess = 0
while guess != 7:
    guess = int(input("Guess: "))
print("Found it!")
Score: