A set of ready-made subprograms that can be imported and used
Which term describes a subprogram that returns a value?
Function
What is meant by an argument?
A value that is passed into a subprogram when it is called
What is meant by a procedure?
A subprogram that executes code but does not return a value
What is meant by importing a library?
Making the subprograms in a library available for use
Which of these is an example of a built-in procedure?
Print
What does the built-in function input do?
It returns the text that the user types in
Which of these subprograms is a function rather than a procedure?
One that returns the average of a set of numbers
In Python, what must you do before using the random.randint function?
Import the random library
Which statement about procedures and functions is correct?
Functions return a value, procedures do not
A programmer needs to generate random numbers in a game. Why is importing a library better than writing these subprograms from scratch?
The subprograms are already written and tested, saving time
A program uses random.randint(1, 6) to simulate the roll of a die. What is returned by this call?
An integer between 1 and 6
Which statement about Print and Random.randint is correct?
Print can be used straight away, Random.randint must be imported
A programmer imports the random library and writes value = random.random(). What is stored in value?
A float between 0.0 and 1.0
Which term describes a subprogram that may take parameters but does not return a value?
Procedure
Which term describes a value that is passed into a subprogram when it is called?
Argument
What is meant by a function?
A subprogram that returns a value to where it was called
What is meant by a parameter?
A named item in the definition of a subprogram that receives a value
Which term describes a variable that can only be used inside the subprogram where it is created?
Local variable
What is meant by the return value of a function?
The result that the function sends back to the point where it was called
Which of these statements about functions and procedures is correct?
A function must return a value but a procedure does not
A programmer writes a subprogram that takes a temperature in Celsius and sends back the value converted to Fahrenheit. What type of subprogram is this?
A function, because it returns a value
A program contains the line answer = sum(5, 3). What happens to the value returned by the sum function?
It is stored in the variable answer
Which of these is a function rather than a procedure?
Random.randint(1, 6)
In the definition def showMenu():, what does showMenu represent?
The name given to the subprogram
A function is defined with the parameters a and b. What are a and b used for inside the function?
Holding the values that are passed in when the function is called
A function must work out the average of a total score and a number of attempts, then give the average back. Which statement must the function contain?
A return statement that sends back the average
Which of these is an advantage of using subprograms in a large program?
Each subprogram can be tested separately before it is used
Functions and procedures are both examples of which term?
Subprogram
A programmer writes def getDate(): so that it takes no values in but sends a date back when it is called. Which statement about getDate is correct?
It is a function because it returns a value
A menu is drawn by a subprogram that is called in several places in a program. When an extra menu option is needed, why does this help?
The menu code only has to be changed in one place
A program contains the line showMenu(). Which statement describes what happens when this line runs?
The code inside the showMenu subprogram is executed
Which term describes the parts of a program in which a variable can be seen and used?
Scope
What is meant by a global variable?
A variable that can be accessed anywhere in a program
Which term describes a variable that only exists while the subprogram it is created in is executing?
Local variable
What is meant by a parameter?
A value that is passed into a subprogram when it is called
Which term describes a variable that is declared in the main program and can be used inside any subprogram?
Global variable
What is meant by scope?
The parts of a program where a variable is recognised
A variable is declared inside a subprogram. Which statement about this variable is true?
It can be used only while that subprogram is executing
What does a subprogram need in order to change the value of a global variable?
The global keyword before the variable name
A local variable in one subprogram has the same name as a local variable in another subprogram. What happens?
Each subprogram uses its own separate variable
Why is it generally recommended to use local variables wherever possible?
They keep a subprogram self-contained so it can be reused
A constant is declared in the main program and used inside a subprogram. What is true?
It can be read in the subprogram but not changed
A program has a global variable called score. A subprogram that wants to update score uses a local variable with the same name instead. What is the result?
The global score keeps its original value
A subprogram needs to read the value of a global variable but does not need to change it. What is needed?
Nothing extra is needed to read the variable
What is printed by this program? total = 10 def show(): total = 3 print(total) show() print(total)
3 then 10
When is it most appropriate to use a global variable rather than a local one?
When several subprograms need to share and update the same value
Look at this program. score = 0 def addPoints(points): bonus = 5 return points + bonus Which one of these is a global variable?
score
We use cookies to enhance your experience. You can manage your preferences or learn more in our Cookie Policy.