PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
A student writes the following code to calculate the average of two numbers: ```python num1 = input("Enter first number: ") num2 = input("Enter second number: ") avg = (num1 + num2) / 2
print("Average:", avg)``` When executed, the code raises a TypeError. What is the most likely cause?
⚠ Common exam trap
Python Institute often tests the misconception that `input()` returns a numeric type when the user types digits, leading candidates to overlook the need for explicit type conversion with `int()` or `float()`.
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, not a number, so arithmetic operations are invalid without conversion
The `input()` function in Python always returns a string, regardless of what the user types. Attempting to use the `+` operator on two strings performs concatenation, not numeric addition, and then dividing a concatenated string by an integer with `/` raises a `TypeError` because the `/` operator is not defined for strings. To fix this, the inputs must be explicitly converted to numbers using `int()` or `float()` before arithmetic operations.
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 division operator '/' is not allowed for integers
Why it's wrong here
Incorrect. '/' works with integers, returning a float.
- ✓
The input() function returns a string, not a number, so arithmetic operations are invalid without conversion
Why this is correct
Correct. input() returns a string; arithmetic requires numeric conversion.
- ✗
The addition operator '+' cannot be used with strings
Why it's wrong here
Incorrect. The '+' operator concatenates strings.
- ✗
The variable names num1 and num2 are reserved keywords
Why it's wrong here
Incorrect. 'num1' and 'num2' are not reserved keywords.
Go deeper
Related to this question
About these practice questions
Courseiva writes every PCEP question from scratch — 498 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 →
Same concept, more angles
1 more way this is tested on PCEP
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. 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?
easy- A.The code uses the wrong operator; it should use the & operator for addition.
- B.The input() function automatically selects the correct type, but the + operator is overloaded to concatenate.
- C.Python automatically converts strings to numbers when using +, but only for integers.
- ✓ D.The input() function returns a string, so + performs string concatenation.
Why D: 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'.
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.