FBISE, NCP & NBF-aligned resources for Classes 9–12
Browse by Class
Browse by Type
Computer Chapter 3 : Topic 6.4
Moving Repeated Code into Functions
1 / 6
Why should duplicated code usually be moved into a function in Python programs?
Reasoning: Placing repeated code inside a function avoids duplication and makes the program easier to update and maintain.
2 / 6
Which Python keyword is used to define a function containing previously duplicated program instructions?
Reasoning: Python uses the $\mathbf{def}$ keyword to create a function that can contain reusable instructions.
3 / 6
A program repeats the same calculation several times. What is the best programming solution?
Reasoning: Repeated calculations should be placed in a reusable function and called whenever they are needed.
4 / 6
What should replace duplicated code after its common instructions have been moved into a function?
Reasoning: After the repeated instructions are moved into a function, each duplicated section can be replaced by a function call.
5 / 6
Which advantage occurs when an error inside duplicated code is corrected after moving it into one function?
Reasoning: Centralizing repeated logic means a bug can be fixed in one place instead of multiple duplicated sections.
6 / 6
A program calculates area repeatedly using different lengths and widths. Which function design is most appropriate?
Reasoning: Using $\mathbf{length}$ and $\mathbf{width}$ as parameters allows the same function to calculate areas for different dimensions.
Your score is
Restart quiz