PCEP input() Practice Question
Exhibit
Refer to the exhibit.
Error output:
Traceback (most recent call last):
File "script.py", line 3, in <module>
result = value + 10
TypeError: can only concatenate str (not "int") to strA developer encounters a TypeError. Which line of code likely caused it?
⚠ Common exam trap
Candidates often assume the error is a ValueError from failed conversion, but the actual error that occurs with option D is a TypeError from using the unconverted string in arithmetic.
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
✓
value = input("Enter a number: ")
The error in question is a TypeError that occurs when a string is used in an arithmetic operation (e.g., adding a string to an integer). Option D returns a string, so subsequent code expecting a number will fail. Options A, B, and C all return numeric types, so they would not cause that specific error.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
value = eval(input("Enter a number: "))
Why it's wrong here
eval() interprets input as code, but risky; would not cause this error if input is number.
- ✗
value = float(input("Enter a number: "))
Why it's wrong here
Convert to float, no error.
- ✗
value = int(input("Enter a number: "))
Why it's wrong here
Convert to int, no error.
- ✓
value = input("Enter a number: ")
Why this is correct
input() returns a string, causing the TypeError.
Go deeper
Related to this question
About these practice questions
This PCEP question is part of Courseiva's 498-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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.