PCEP Computer Programming and Python Fundamentals Practice Question
A developer writes a function that calculates the area of a rectangle and prints the result inside the function. Later, they need to use this area in another calculation. What should they do to make the function reusable and composable?
⚠ Common exam trap
The PCEP exam often tests the distinction between printing a value and returning a value, exploiting the common beginner misconception that printing makes the value available for later use in code.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Modify the function to return the area instead of printing it.
Returning a value from a function allows the caller to capture and reuse that value in subsequent calculations, making the function composable and reusable. Printing the result inside the function (as in the original code) only outputs it to the console and discards the value, preventing further programmatic use. By modifying the function to return the area, the developer can assign the result to a variable and use it in other expressions.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Store the area in a global variable and access it later.
Why it's wrong here
A global variable couples the function to external state, so the area is not returned and the function cannot be reused or composed cleanly. Globals suit small scripts sharing configuration, but returning the value is what enables composition.
- ✓
Modify the function to return the area instead of printing it.
Why this is correct
Returning the area rather than printing it lets callers capture the value in a variable and feed it into further calculations, satisfying the stem's requirement for reusability and composability. Printing only emits output to stdout, leaving no usable value for subsequent computation.
- ✗
Keep the function as is and call it from inside another function.
Why it's wrong here
Printing inside the function discards the value, so callers cannot reuse it; returning the area lets other code consume it. Keeping the print and wrapping the call still yields no usable value. Printing suits scripts where output alone is the goal, not composable calculations.
- ✗
Pass the area to the next calculation using a print function argument.
Why it's wrong here
Passing the area into print still only displays it; print returns None, so the value cannot feed a further calculation. Printing suits debugging or user-facing output, whereas returning the area from the function is what makes it reusable and composable.
Go deeper
Related to this question
About these practice questions
Courseiva writes every PCEP question from scratch — 482 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This PCEP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCEP exam.