You should be able to:
•• only exist while the subroutine is executing
•• are only accessible within the subroutine.
The key advantages of subroutines are:
Parameter - The variable name for a value that is passed to a subroutine
Argument - The actual value that is passed to a subroutine
def add(a,b):
c = a + b
return (c)
print (add(5,3))
Arguments are passed through the parameters to solve a problem. In this case, 5 and 3 are passed through the parameters and are added together.
We have returned a value in the example above. If I wanted to use that value then I could store it into a variable.
def add(a,b):
c = a + b
return (c)
c=(add(5,3))
print (c)
When we look at scope of variables, there are two main types:
The example function above contains a local variable called c. This variable can only be accessed from within the subroutine. If you deleted the line of code that reads c=(add(5,3))
then it would say that c doesn't exist.
A menu of programs
Create a menu for all of the programs that you have developed so far. These could be:
The user should see a menu of the programs and be able to select which one they wish to run.
After running the program they should then return to the menu or quit.
SOURCE RECOGNITION - PLEASE NOTE: The examination examples used in these walking talking mocks are samples from AQA from their non-confidential section of the public site. They also contain questions designed by TeachIT for AQA as part of the publicly available lesson materials.