Subroutines: Cambridge IGCSE practice
Functions, procedures, parameters and scope. 16 questions in the style of the Cambridge IGCSE exam.
Sample questions
What is the main difference between a function and a procedure?
- A function returns a value; a procedure does not
- A procedure can have parameters; a function cannot
- A function must print something
- There is no difference in Python
What does this program print?
def greet(name, times):
for i in range(times):
print("Hi " + name)
greet("Sam", 2)
greet("Jo", 1)Which statement about local variables is true?
- They can be used anywhere in the program
- They only exist while the subroutine they are declared in is running
- They keep their value between calls
- They must be declared with the keyword global