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
Global variables violate best practices and can cause side effects.
- ✓
Modify the function to return the area instead of printing it.
Why this is correct
Returning allows the result to be used in other calculations.
- ✗
Keep the function as is and call it from inside another function.
Why it's wrong here
The function prints, so the result is not accessible programmatically.
- ✗
Pass the area to the next calculation using a print function argument.
Why it's wrong here
Print returns None, so you cannot pass its output as an argument.
Go deeper
Related to this question
About these practice questions
Courseiva writes every PCEP question from scratch — 498 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.