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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Parameters

A
  • A variable that is used as an input to the sub-program.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Function vs Procedure

A
  • A function returns a value
  • A procedure does not return a value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly