PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
A student writes the following code:
name = "Alice" age = 25
print("Name: " + name + ", Age: " + age)What happens when the code runs?
⚠ Common exam trap
The trap here is thinking that Python automatically converts types during string concatenation, as some languages do, when in fact it requires explicit conversion.
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
✓
A TypeError is raised because you cannot concatenate a string and an integer.
In Python, the + operator cannot combine a string and an integer. The expression attempts to concatenate the string literal with the integer variable age, which raises a TypeError. To fix this, the integer must be converted to a string using str(age) or formatted using an f-string or the format() method.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
It raises a SyntaxError before execution.
Why it's wrong here
The code is syntactically valid; the error occurs at runtime when the interpreter tries to evaluate the concatenation. A SyntaxError would be raised during parsing if there were invalid syntax, but here the problem is a type mismatch during execution.
- ✗
It prints: Name: Alice, Age: age
Why it's wrong here
The code does not treat age as a literal string. The variable age holds an integer, and the concatenation fails before any output is produced. Therefore, the output is not a string containing the word 'age'.
- ✗
It prints: Name: Alice, Age: 25
Why it's wrong here
Python does not automatically convert the integer age to a string during concatenation. The + operator requires both operands to be strings. Since age is an int, the expression raises a TypeError instead of producing the intended output.
- ✓
A TypeError is raised because you cannot concatenate a string and an integer.
Why this is correct
The + operator between a string and an integer is not allowed. Python raises a TypeError with a message like 'can only concatenate str (not "int") to str'. The age variable is an integer, so the concatenation fails at runtime.
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 and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Python Institute exam blueprint
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.