PCEP Computer Programming and Python Fundamentals Practice Question
A programmer needs to store the number of items in a shopping cart. The value will be a whole number and may be used in arithmetic operations. Which Python data type is most appropriate for this variable?
⚠ Common exam trap
The trap here is assuming any numeric type works, but float may cause rounding and str will concatenate instead of add.
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
✓
int
The number of items in a cart is a whole number used in arithmetic, so int is the correct type. Floats are for decimal values and can introduce rounding, strings are text and would break calculations, and booleans only represent truth values. Using int keeps the data accurate and operations predictable.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
bool
Why it's wrong here
A bool holds only True or False. It cannot represent arbitrary whole numbers like 1, 2, or 10. While True and False can act as 1 and 0 in arithmetic, that is a side effect and not intended for storing counts. It would lose information about the actual number of items.
- ✓
int
Why this is correct
An int represents whole numbers without a fractional part, which fits the count of items in a cart. It supports arithmetic operations like addition or multiplication. Since the quantity is always a whole number, int avoids unnecessary decimal precision and is the idiomatic choice for counts.
- ✗
str
Why it's wrong here
A string stores text, not numbers. If the cart count were stored as a string, arithmetic operations would fail or concatenate instead of adding. For example, '5' + '3' yields '53', not 8. This is unsuitable for a numeric value that must be used in calculations.
- ✗
float
Why it's wrong here
A float stores numbers with decimal points. While it can hold whole numbers, it introduces floating-point representation and potential rounding issues. For a count of items, which is inherently discrete, a float is unnecessarily complex and could lead to subtle errors when comparing values.
Go deeper
Related to this question
About these practice questions
Courseiva writes every PCEP question from scratch — 482 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 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.