PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
A developer needs to read an integer from user input and store it. Which code snippet accomplishes this?
⚠ Common exam trap
Python Institute often tests the distinction between calling a function (with parentheses) and referencing it (without parentheses), so candidates mistakenly write `int(input)` instead of `int(input())`.
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
✓
x = int(input())
`int(input())` first calls `input()` to read a string from the user, then passes that string to `int()` to convert it to an integer. This is the standard Python pattern for reading an integer from standard input.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
x = int(input())
Why this is correct
input() returns a string, so int() converts that string into an integer before assignment to x. This satisfies the requirement to read and store an integer, whereas storing the raw input would leave x as a string and break later arithmetic.
- ✗
x = read_int()
Why it's wrong here
read_int() is not a Python built-in or standard-library function, so it raises a NameError at runtime. The name is tempting because it describes the desired outcome, but Python reads input as a string via input(), which must then be converted with int() to store an integer.
- ✗
x = input(int())
Why it's wrong here
int() requires a value to convert, so calling it with no argument raises a TypeError before input() ever runs. It is tempting because it combines the two needed operations, but the correct form nests input() inside int(), reading the string first and then converting it.
- ✗
x = int(input)
Why it's wrong here
int(input) passes the function object itself to int(), raising a TypeError rather than reading anything. It is tempting because both required names appear, but the parentheses are misplaced: input() must be called first, then its returned string passed to int().
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 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.