Font size
WorksheetsProcedure & Functions
Total questions: 16
Worksheet time: 10mins
What is a Subroutine?
a block of code that performs a specific task
A long piece of code that does not use indentation
A type of iteration
a block of code named def
When creating a subroutine, when we have values placed in the brackets, what is this called?
e.g. def sub1(data1, data1) :
parameter
argument
var
Tick the advantages of using subroutines
•Allows you to break the code down into chunks
•easier to read and maintain
•Easier to debug as errors are easier to spot as they are contained into the subroutines
•Allows you to test them independently
•Allows you to add in lots of repeated code to the program
Leo wants to create a subroutine that will roll a dice. Which syntax is correct?
def dice roll ():
def diceroll ()
def diceroll ():
def diceroll []:
The subroutines must be defined BEFORE the main program is written.
True or False?
True
False
Which subroutine does not return any data?
Condition
Loop
Procedure
Function
What is the keyword used to declare a procedure in Python?
def
procedure
function
proc
Does your subroutine code require indentation?
Yes
No
Sometimes
Using "meaningful identifiers" means...
Giving variables and subroutines sensible names
Giving variables the correct data type
Correct use of conditions in loops
What is the term for a named block of code that can be executed by writing its name.
Subroutine
Condition
Selection
What are the parameters with in this procedure?
first name and second name
first and surname
first and second name
myname, first and surname
What happens if you call a subroutine before defining it in Python?
The program will crash
The subroutine will be activated
The computer will look for the subroutine and not find it
The program will continue without any issues
Can a subroutine have multiple parameters?
No, a subroutine can only have one parameter
Yes, a subroutine can have as many parameters as needed
Yes, but there is a limit to the number of parameters
No, a subroutine cannot have any parameters
How should subroutines be structured in Python?
All subroutines should be placed at the top of the code
Subroutines should be called before they are defined
Subroutines should have the same name as the main program
Subroutines should be indented using spaces
