Sub-Programs
No description yet. This curated deck is ready for daily study.
Card preview (5)
How to create a sub-program in Python:
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
How to call a sub-program in Python
• 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.
Parameters
• A variable that is used as an input to the sub-program.
Example of parameters in sub-programs using a simple addition program where the user inputs two numbers.
• 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)
Function vs Procedure
• A function returns a value • A procedure does not return a value