PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
A junior developer is writing a script to calculate the total cost of items in a shopping cart. The script uses variables item_price (float) and quantity (int). The code is:
item_price = 2.5 quantity = 3 total = item_price * quantity
print("Total: " + total)When run, this code raises a TypeError. The developer is confused because the multiplication seems correct. What is the most likely issue and the correct fix?
⚠ Common exam trap
Python Institute often tests the distinction between arithmetic operations (which work across numeric types) and string concatenation (which requires explicit type conversion), trapping candidates who assume Python will automatically convert a float to a string when using the `+` operator.
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
✓
The print function cannot concatenate a string with a float; convert total to string using str(total).
The `print` function in Python expects all arguments to be strings when using the `+` operator for concatenation. The variable `total` is a float (result of multiplying a float by an int), and Python does not implicitly convert it to a string. The error is a `TypeError: can only concatenate str (not 'float') to str`. The fix is to explicitly convert `total` to a string using `str(total)` before concatenation.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
The variable total is being overwritten by the print statement; use a different variable name.
Why it's wrong here
total is not overwritten by print.
- ✗
The multiplication should be written as int(item_price) * quantity to ensure integer result.
Why it's wrong here
The multiplication already works; converting to int would lose precision.
- ✗
The variable names are too descriptive; rename them to a and b to avoid confusion.
Why it's wrong here
Descriptive names are good practice.
- ✓
The print function cannot concatenate a string with a float; convert total to string using str(total).
Why this is correct
Concatenation requires both operands to be strings.
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.