Subroutines (Functions and Procedures)

Key Term: Function returns a value

OCR Pseudocode Python Result
function add(firstNum, secondNum)

      total = firstNum + secondNum

return total

endfunction

totalScore = add(5,3)

def add(firstNum, secondNum):

  total = firstNum + secondNum

  return total

totalScore = add(5,3)

This this function takes two arguments (inputs) which are firstNum and secondNum and returns the total of the two added together.

This calls the function and assigns the returned value to the variable totalScore

Procedures

 

Key Term: Procedure does not return a value

 

OCR Pseudocode Python Output (Result)
procedure showNames(firstName,lastName)

print(“Your name is: “)

print(firstName + lastName)

endprocedure

showNames(“Sam”, “Green”)

def showName(firstName, lastName):

   print(“Your name is: “)

   print(firstName + lastName)

showNames(“Sam”, “Green”)

Your name is: Sam Green

This procedure has two arguments

(inputs) which are  firstName and lastName. When the procedure is called the names are concatenated together.

Scroll to Top