PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
An accountant uses a Python script to calculate tax: tax = price * 0.08. For price=19.99, tax results in 1.5992. However, the output should be rounded to two decimal places. Which expression should replace the current one?
⚠ Common exam trap
Python Institute often tests the distinction between `round(x)` (rounds to integer) and `round(x, n)` (rounds to n decimal places), and the trap here is that candidates may choose Option A thinking it rounds to two decimals, or Option D thinking integer truncation is equivalent to rounding.
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
✓
tax = round(price * 0.08, 2)
The built-in `round()` function with a second argument of 2 rounds the floating-point result of `price * 0.08` to exactly two decimal places, which matches the requirement for currency formatting. The other options either omit rounding, round to an integer, or use integer truncation that can produce incorrect results for negative numbers or edge cases.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
tax = round(price * 0.08)
Why it's wrong here
round() with no second argument rounds to the nearest integer, giving 2.0 rather than 1.60. It would be correct when whole-number results are wanted, but the stem requires two decimal places, which needs the ndigits argument.
- ✓
tax = round(price * 0.08, 2)
Why this is correct
The built-in round() function returns a float rounded to the specified number of decimal places, so round(price * 0.08, 2) yields 1.6 for price=19.99, satisfying the two-decimal constraint. Unlike formatting, it changes the numeric value itself, keeping tax usable in further arithmetic.
- ✗
tax = price * 0.08
Why it's wrong here
No rounding applied.
- ✗
tax = int(price * 0.08 * 100) / 100
Why it's wrong here
Truncates instead of rounding.
Go deeper
Related to this question
About these practice questions
One of 482 original PCEP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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.