Sub Programs

Lesson Instructions

Watch and follow the YouTube video, the lesson contains three parts:

  1. Key Information and content - all you need to do here is watch and listen. We recommend you take some notes for this one!

  2. Learning activity - You are to complete the activity, by writing sub programs. The first will be a sorting task, the second will be writing it yourself.

  3. Consolidation - these are past exam question and are for deliberate practice to check your understanding.

Task - Sub Programs Activity

Task - Exam Questions - Deliberate Practice

Exam Questions - Web

Mark Scheme

Question 1

1 mark per bullet to max 4

  • Function defined called newbalance...

  • ....that allows two parameters to be passed in

  • Correct balance calculated using these parameters

  • Value returned

Example Pseudocode

function newbalance(balance,cost)

newcost = balance - cost

return newcost

endfunction

Bullet points 3 and 4 may be combined into one line (e.g. return balance-cost). Parameters can have any sensible identifiers. Allow any sensible attempt to return a value for bullet point 4, even if this is not the correct new balance.

Question 2

1 mark per bullet

  • Program calls function correctly using hours and minutes variables

  • Parameters used appropriately

  • Calculation is computed accurately

  • Final total is returned suitably

Example solution:

hours = input("Please enter number of hours played:")

minutes = input("Please enter number of minutes played:")

finalTotal = totalMins(hours, minutes)

print(finalTotal)


function totalMins(hours, minutes)

total = hours + mins * 60

return total

endfunction

  1. Parameters name in the function must be used within the function itself

  2. Does not matter if function uses different names to those declared in the main program

  3. Return must be included with the correct local variable for total