Modular Power 0 / 26
Modular Rank Action Scripter

Topic 2.2.10: Sub-programs

Functions, Procedures, Scope & Parameters.

1 [2 Marks]
......................... calculate_area(width, height) area = width * height ......................... area endfunction
Fill blanks (OCR Reference Language / Python).
✅ Mark Scheme
  • function / def
  • return
Score:
2 [2 Marks]
Difference between Function and Procedure?
✅ Mark Scheme

Function: Returns a value.

Procedure: Does NOT return a value (just performs an action).

Score:
3 [2 Marks]
score = 10 def update_score(): score = 50 print(score) update_score() print(score)
What is the output?
✅ Mark Scheme
50
10

Explanation: `update_score` creates a new local variable `score`. The global `score` remains 10.

Score:
4 [3 Marks]
01 function check_password(user_input) 02 user_input = input("Enter password: ") 03 if user_input == "SeCrEt" then ...
(a) Line causing Logic Error?
(b) Why?
✅ Mark Scheme

(a) Line 02

(b) The parameter `user_input` is overwritten by a new input inside the function, making the passed argument useless and the function not reusable.

Score:
5 [3 Marks]
def math_trick(a, b): c = a + b if c > 10: return c else: return c * 2 print(math_trick(5, 3))
What is the output?
a b c Output
✅ Mark Scheme

16

(c=8. 8 is not > 10. Returns 8 * 2).

Score:
6 [6 Marks]
Create function get_discount(price).
- If price > 100, apply 10% discount (price * 0.9).
- Else price remains same.
- Return limit.
✅ Mark Scheme
function get_discount(price)
  if price > 100 then
    price = price * 0.9
  endif
  return price
endfunction

Note: Can also use return price inside if/else blocks.

Score:
7 [5 Marks]
(a) Better technique for repeated code?
(b) Two benefits?
✅ Mark Scheme

(a) Use a Sub-program (Function/Procedure).

(b) Code Reusability (write once, use many times), Easier Maintenance/Debugging (fix in one place), Decomposability (break down complex problems).

Score:
8 [1 Mark]
result = calculate_area(5, 10)
Are 5 and 10 Parameters or Arguments?
✅ Mark Scheme

Arguments. (Parameters are the variable names in the definition).

Score: