Logic Power 0 / 40
Logic Rank Boolean Novice

Topic 2.2.2: Programming Advanced

Operators, Logic, Loops & Refining Code.

1 [4 Marks]
Calculate the result:
  • 10 / 2
  • 10 DIV 3 (or // )
  • 10 MOD 4 (or % )
  • 2 ^ 4 (or ** )
✅ Mark Scheme
  • / : 5.0 (Float division)
  • DIV : 3 (Integer division)
  • MOD : 2 (Remainder of 10/4 is 2)
  • ^ : 16 (2*2*2*2)
Score:
2 [3 Marks]
Given x = 5, y = 10. True or False?
  • x > 5 OR y == 10
  • x < 10 AND y != 10
  • NOT (x == 5)
✅ Mark Scheme
  • True (Second part is true)
  • False (Second part is false, y IS 10)
  • False (x IS 5, so True becomes False)
Score:
3 [3 Marks]
Difference between average = total / count and average = total DIV count?
Why does data type matter?
✅ Mark Scheme

/ keeps the decimal value (Float), while DIV removes it (Integer).

Score:
4 [3 Marks]
(a) Symbol for Assignment?
(b) Symbol for Comparison (Equal to)?
(c) Write code to check if score is 100.
✅ Mark Scheme

(a) =

(b) ==

(c) if score == 100:

Score:
5 [4 Marks]
age = int(input("Enter age: ")) if age > 13 OR age < 19: print("You are a teenager") else: print("You are not a teenager")
(a) Why is this wrong? Give an example.
(b) Correct the code.
✅ Mark Scheme

(a) OR means only one side needs to be true. 100 is > 13, so it prints "Teenager".

(b) if age >= 13 AND age <= 19:

Score:
6 [2 Marks]
price = 10 print("The price is " + price)
Explain the error using technical terms.
✅ Mark Scheme

Runtime Error / TypeError: You cannot concatenate a String with an Integer without casting.

Score:
7 [5 Marks]
a = 10 b = 2 c = 0 WHILE a > b a = a - 2 b = b + 1 c = c + b ENDWHILE print(c)
Trace the loop. What is the value of c printed?

Trace Table:

abcOutput
✅ Mark Scheme

1. a=8, b=3, c=3

2. a=6, b=4, c=7

3. a=4, b=5, c=12

End loop (4 is not > 5)

Output: 12

Score:
8 [2 Marks]
Open gate IF: Alarm is OFF And (Keycard OR MasterCode).
Fill in the blanks:
if (NOT alarm) ______ (keyCard == True ______ masterCode == True)
✅ Mark Scheme

1. AND

2. OR

Score:
9 [4 Marks]
id = int(input("Enter ID")) if id == 1: print("Red") if id == 2: print("Red") if id == 3: print("Red") if id == 4: print("Blue") if id == 5: print("Blue") if id == 6: print("Blue")
Rewrite efficiently using range checks (>=, <=, AND/OR).
- 1-3: Red
- 4-6: Blue
- Else: Spectator
✅ Mark Scheme
if id >= 1 and id <= 3:
    print("Red")
elif id >= 4 and id <= 6:
    print("Blue")
else:
    print("Spectator")
Score:
10 [6 Marks]
Write a program:
  • Input whole number.
  • Output "Even" or "Odd".
  • If > 0 AND multiple of 10: "Big Ten".
  • If < 0: "Negative number" .
✅ Mark Scheme
num = int(input("Enter num: "))

if num % 2 == 0:
    print("Even")
else:
    print("Odd")

if num > 0 and num % 10 == 0:
    print("Big Ten")

if num < 0:
    print("Negative number")
Score:
11 [2 Marks]
Record Product has Stock field.
Write code to decrease item1's stock by 5.
✅ Mark Scheme

item1.Stock = item1.Stock - 5

Score: