Sub-Programs Flashcards
1
Q
How to create a sub-program in Python:
A
1 - define it by using ‘def’.
2 - give it a name e.g message 1
3 - the code we then want to be part of the sub-program is indented
2
Q
How to call a sub-program in Python
A
- By writing out the name of the sub-programs e.g message1 and adding brackets represents us wanting the code inside those sub-programs to execute.
3
Q
Parameters
A
- A variable that is used as an input to the sub-program.
4
Q
Example of parameters in sub-programs using a simple addition program where the user inputs two numbers.
A
- def addition (x, y):
- z = x + y
- print(z)
- x = int(input(“Please enter your first number - “)
- y = int(input(“Please enter your second number - “)
- addition(x,y)
5
Q
Function vs Procedure
A
- A function returns a value
- A procedure does not return a value