Courseiva

PCEP Computer Programming and Python Fundamentals Practice Question

What function is used to read input from the user in Python 3?

⚠ Common exam trap

The PCEP exam often tests the distinction between Python 2 and Python 3 input functions, trapping candidates who remember `raw_input()` from Python 2 or who think `sys.stdin.readline()` is the standard way to read user 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

✓

input()

In Python 3, the built-in `input()` function reads a line from standard input and returns it as a string. This is the standard and simplest way to capture user input, replacing the Python 2 `raw_input()` function.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    read_input()

    Why it's wrong here

    read_input() is not a Python built-in and raises NameError, since Python 3 provides input() for reading user input. It is tempting because the name describes the task, and a user-defined helper function called read_input() would legitimately be correct in a custom codebase.

  • ✗

    sys.stdin.readline()

    Why it's wrong here

    sys.stdin.readline() reads from the standard input stream directly, returning a string including the trailing newline, and requires importing sys. The question asks for the built-in function, which is input(). sys.stdin.readline() suits scripts processing piped or redirected data where newline preservation and stream-level control matter.

  • ✓

    input()

    Why this is correct

    The built-in `input()` function reads a line from standard input, pauses execution until the user presses Enter, and returns the entered text as a string. This directly satisfies the Python 3 requirement, unlike `raw_input()`, which was renamed to `input()` in Python 3 and no longer exists.

  • ✗

    raw_input()

    Why it's wrong here

    raw_input() was renamed to input() in Python 3, so it raises NameError; it existed only in Python 2. It is tempting because Python 2 tutorials and legacy code still use it, and it would be correct when maintaining Python 2 scripts.

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 →

How Courseiva writes practice questions · Editorial policy

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.