Save
...
Topic 6: Problem Solving with Programming
6.2 Writing Programs
6.2.4 Applying subprograms:
Save
Share
Learn
Content
Leaderboard
Share
Learn
Cards (102)
Subprograms improve program organization and reduce code duplication.
True
Procedures do not return a
value
Using subprograms reduces code
duplication
Order the steps involved in using subprograms in a larger program.
1️⃣ Design the subprogram
2️⃣ Define the subprogram
3️⃣ Call the subprogram
4️⃣ Pass data to the subprogram
5️⃣ Return a value (if a function)
Match the type of subprogram with its purpose:
Functions ↔️ Compute and return a value
Procedures ↔️ Perform actions or modify program state
One benefit of subprograms is reduced code
duplication
Parameters allow subprograms to operate on different
data
Functions in Python are defined using the
def
keyword.
The `add` function in
Python
returns a value when called.
True
Functions in Python must always
return
a value after execution.
True
What is the key difference between a function and a procedure in Python?
Procedures do not return values
When calling a subprogram in Python, you pass
arguments
Match the subprogram feature with its description:
Return Value ↔️ Yes for Functions, No for Procedures
Purpose ↔️ Compute and return values or perform actions
What is the primary task of a function in Python?
Compute and return a value
A function in Python can calculate the area of a rectangle by accepting parameters such as
length
and width
When calling a subprogram with parameters, you must provide the necessary
arguments
.
True
Subprograms can accept inputs called
parameters
In Python, functions and procedures are defined using the
def
keyword.
Procedures in Python do not return a
value
Subprograms reduce code
duplication
by allowing the same code block to be used multiple times.
Steps to call a subprogram in Python
1️⃣ Use the subprogram's name
2️⃣ Provide required arguments
3️⃣ Enclose arguments in parentheses
Calling a procedure requires capturing its return value.
False
Returning values from functions allows for modular design by
encapsulating
functionality.
True
Unit testing involves verifying the correctness of each
subprogram
in isolation.
True
Arguments provide the actual values for the
parameters
What is the purpose of unit testing in programming?
Verify subprogram correctness
Testing edge cases involves using boundary or extreme input values.
True
By thoroughly testing and debugging subprograms, you can identify and fix issues early in the
development
Procedures are used to perform actions or modify program
state
Why are individual subprograms easier to test and debug?
Smaller, manageable units
Match the parameter type with its description:
Required Parameters ↔️ Must be provided when called
Default Parameters ↔️ Have default values
Default parameters can be overridden when calling the subprogram.
True
Procedures in Python do not have a return statement.
True
When calling a subprogram, you pass
arguments
Functions
in Python are subprograms that
return
a value after execution.
Procedures
in Python do not return a value.
True
Steps to define a function in Python
1️⃣ Use the `def` keyword
2️⃣ Specify the function name
3️⃣ Include parameters in parentheses
4️⃣ Add a return statement if needed
What is an example of calling a procedure in Python?
greet("Alice")
What can you do with the return value of a function in Python?
Capture and use it
Return values in Python are used to pass data back to the
caller
of a function.
See all 102 cards