Courseiva

PCEP Practice Question: Data Types, Variables, Basic I/O and Operators

A junior developer writes: result = input("Enter first: ") + input("Enter second: ") and then prints result. When entering 5 and 3, the output is '53'. Which explanation is correct?

⚠ Common exam trap

Watch out — candidates often assume `input()` returns a numeric type when numbers are entered, or that Python's dynamic typing will automatically convert strings to numbers for addition, leading them to choose option B or C instead of recognizing the default string behavior.

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() function returns a string, so + performs string concatenation.

The `input()` function in Python always returns a string, regardless of what the user types. When the `+` operator is used with two strings, it performs concatenation, not arithmetic addition. Thus, entering 5 and 3 results in the strings '5' and '3' being joined to produce '53'.

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 code uses the wrong operator; it should use the & operator for addition.

    Why it's wrong here

    & is a bitwise operator, not addition, and would raise a TypeError on strings. The real cause is that input() returns str, so + concatenates. It tempts because the output looks like a wrong-operator bug, yet the operator is behaving correctly for the operand types supplied.

  • ✗

    The input() function automatically selects the correct type, but the + operator is overloaded to concatenate.

    Why it's wrong here

    input() always returns str regardless of content, so no type selection happens; the + operator is not overloaded here, it simply concatenates two strings. It tempts because operator overloading genuinely exists in Python for numeric types, but str + str is ordinary concatenation, not overload resolution between int and str.

  • ✗

    Python automatically converts strings to numbers when using +, but only for integers.

    Why it's wrong here

    Python never coerces strings to numbers for +; both input() results remain str, so + concatenates '5' and '3' into '53'. The claim about integers is fabricated. It tempts because implicit numeric conversion does occur in arithmetic contexts like int + int, but that requires explicit casting via int() before the operator.

  • ✓

    The input() function returns a string, so + performs string concatenation.

    Why this is correct

    input() always yields a str, never a number, so the + operator concatenates the two strings rather than adding them. Entering 5 and 3 therefore produces '53', confirming that string concatenation, not arithmetic addition, is performed.

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 →

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.