PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
A cashier script stores a price as a string and needs to apply a 10 percent discount. The code is:
price = "19.99" discount = 0.10 final = price * (1 - discount)
print(final)
What happens when this code runs?
⚠ Common exam trap
The trap here is expecting Python to convert numeric-looking strings to numbers automatically during arithmetic, which it never does.
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
✓
It raises a TypeError because a string cannot be multiplied by a float.
The * operator supports string repetition only when the other operand is an integer. Here the other operand is the float 0.9, so Python raises TypeError. To compute the discounted price the code must first convert the string to a number, for example float(price) * (1 - discount), and only then print the result.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
It prints "19.99" repeated zero times, resulting in an empty string.
Why it's wrong here
String repetition requires an integer count, not a float. The expression (1 - discount) yields 0.9, which is a float, so the * operator cannot use it as a repetition count. Even if the count were 0, that path would require an int; the float prevents it and a TypeError is raised instead.
- ✗
It prints 199.9 because the decimal point is ignored during multiplication.
Why it's wrong here
Python never ignores characters inside a string during arithmetic; it does not parse numeric text implicitly. The string "19.99" is not treated as the number 19.99, so no numeric multiplication occurs. The actual outcome is a TypeError, not a numeric result.
- ✓
It raises a TypeError because a string cannot be multiplied by a float.
Why this is correct
Multiplying a str by an int repeats the string, but multiplying a str by a float is unsupported and raises TypeError. Since price is still the string "19.99" and (1 - discount) evaluates to the float 0.9, the * operator fails. The script must convert price with float(price) before the arithmetic can succeed.
- ✗
It prints 17.991 because Python converts the string automatically.
Why it's wrong here
Python does not perform implicit string-to-number conversion for arithmetic. The expression (1 - discount) is a float, but price remains a string, so the multiplication cannot proceed numerically. No automatic coercion occurs here, so the printed value would not be a numeric product.
Go deeper
Related to this question
About these practice questions
This PCEP question is part of Courseiva's 482-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 →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Python Institute exam blueprint
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.