PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
A developer is writing a program to calculate the average of three test scores. The current code reads scores as integers: a=int(input()); b=int(input()); c=int(input()); avg = (a+b+c)/3; print(avg). For scores 7, 8, and 9, the output is 8.0, but the requirement is to print the integer average (8), rounded to the nearest whole number. Which modification should the developer make to meet the requirement?
⚠ Common exam trap
Python Institute often tests the distinction between truncation (`int()`) and rounding (`round()`), leading candidates to mistakenly choose `int(avg)` because they think converting to int removes decimals, but it truncates rather than rounds.
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
✓
Use round(avg): print(round(avg))
The requirement is to print the integer average rounded to the nearest whole number. Using `round(avg)` correctly rounds the floating-point result (8.0) to the nearest integer (8) and prints it as an integer, satisfying the requirement. Option D is correct because `round()` performs standard rounding (banker's rounding in Python 3) and returns an integer when called with a single argument.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Use integer division after multiplying sum
Why it's wrong here
Truncates, same as integer division.
- ✗
Use integer division: avg = (a+b+c)//3
Why it's wrong here
Integer division truncates, does not round (e.g., 8.9 becomes 8).
- ✗
Use int(avg): print(int(avg))
Why it's wrong here
int truncates, does not round.
- ✓
Use round(avg): print(round(avg))
Why this is correct
Correct; round rounds to nearest integer.
Go deeper
Related to this question
About these practice questions
This PCEP question is part of Courseiva's 498-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
Same concept, more angles
1 more way this is tested on PCEP
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. A program uses 'x = 3.14' and 'y = int(x)'. What is the value of y?
medium- A.4
- B.3.14
- C.Error
- ✓ D.3
Why D: The int() function in Python truncates the decimal part of a float, converting 3.14 to the integer 3. It does not round to the nearest whole number.
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.