PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
A developer writes a script to read user input using input() and then prints it. However, the program crashes when the user enters a number. What is the most likely cause?
⚠ Common exam trap
Python Institute often tests the misconception that `input()` can return different types based on the input, when in Python 3 it always returns a string, leading candidates to overlook the need for explicit conversion.
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 input is read as a string, but the code treats it as a number without conversion.
The `input()` function in Python 3 always returns a string, regardless of what the user types. If the user enters a number, the program may crash if the code later performs an operation (like arithmetic or comparison) on that string without first converting it to an integer or float using `int()` or `float()`. This mismatch between the string type and the expected numeric type causes a `TypeError`.
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 input is read as a string, but the code treats it as a number without conversion.
Why this is correct
The crash occurs because `input()` always returns a string, so any arithmetic or numeric comparison on that value raises a `TypeError`. The stem's constraint is unhandled numeric use of raw input; converting with `int()` or `float()` before operating on the value resolves it.
- ✗
The script uses Python 2, where input() evaluates input as code.
Why it's wrong here
Python 2's input() evaluates the entered text as Python code, so typing a number returns an int and works; typing a name raises NameError. The scenario specifies a number causing the crash, which contradicts this behaviour. This option would fit a crash on non-numeric text under Python 2.
- ✗
The print() function expects a string, but the input is a number.
Why it's wrong here
print() accepts any object and converts it to its string representation, so passing an int raises no error. The function is designed for arbitrary types; the crash originates in input() or later processing, not in printing. This option would apply only if print() were given an incompatible argument in a different context.
- ✗
The input() function cannot handle numeric input.
Why it's wrong here
input() returns whatever the user types as a string, including digits, so numeric entry alone does not crash it. The function is designed precisely for reading user-supplied text; the crash stems from how that string is subsequently used, such as arithmetic without conversion.
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.