Courseiva

PCEP Practice Question: Data Types, Variables, Basic I/O and Operators

A script calculates total cost: price = 49.95, quantity = 3, tax_rate = 0.08. The developer writes: total = price * quantity * (1 + tax_rate). The result is printed as 161.838. Which best practice is being violated?

⚠ Common exam trap

Python Institute often tests the misconception that any arithmetic result is acceptable as long as the formula is correct, but the trap is that currency values require explicit rounding to two decimal places to follow financial best practices.

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

✓

Not rounding the result to two decimal places for currency.

When dealing with currency values, best practice dictates rounding to two decimal places to represent cents. The raw result 161.838 is not a valid monetary amount; it should be rounded to 161.84 using `round(total, 2)` or formatted with `:.2f`. This ensures accuracy and avoids confusion in financial calculations.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    Using parentheses unnecessarily.

    Why it's wrong here

    Parentheses here group the tax multiplier (1 + tax_rate), which is required for correct precedence; removing them changes the calculation. Parentheses are unnecessary only when default operator precedence already produces the intended grouping, as in a + b * c.

  • ✗

    Not using an f-string to format the output.

    Why it's wrong here

    The stem asks about the calculation producing 161.838, not about display formatting. An f-string would round the printed value, but the underlying float still carries the same result; f-strings are correct when readable, rounded output is the goal.

  • ✓

    Not rounding the result to two decimal places for currency.

    Why this is correct

    Currency values require two decimal places, but the calculation produces 161.838, an unrounded float. Floating-point arithmetic introduces representation error, so monetary results must be rounded, typically with round() or Decimal, to avoid displaying fractional cents. This violates the best practise of rounding currency output.

  • ✗

    Using multiplication instead of addition for tax.

    Why it's wrong here

    Multiplication is the correct operation: tax is a rate applied to the subtotal, so price * quantity * (1 + tax_rate) is right. Addition would be correct only if tax_rate were an absolute currency amount rather than a proportion.

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 →

How Courseiva writes practice questions · Editorial policy

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.