PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
A student tries to write a program that prints the square of a number. The code:
num = 5
print("The square is " + num ** 2)When run, a TypeError occurs. Which of the following fixes the error and produces exactly the output 'The square is 25'?
⚠ Common exam trap
Python Institute often tests the distinction between concatenation with `+` (which requires matching types) and the `print()` function's multiple arguments with commas (which automatically adds a space separator but does not require type conversion), leading candidates to mistakenly choose Option C when the exact output string must match.
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
✓
Change to: print("The square is " + str(num ** 2))
It converts the integer result of `num ** 2` (which is 25) to a string using `str()`, allowing concatenation with the string literal `"The square is "`. Without this conversion, Python raises a `TypeError` because the `+` operator cannot concatenate a string and an integer directly.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
Change to: print("The square is " + str(num ** 2))
Why this is correct
str() converts the integer to string for concatenation.
- ✗
Change to: print("The square is " + num ** 2)
Why it's wrong here
Same error as original; no conversion.
- ✗
Change to: print("The square is", num ** 2)
Why it's wrong here
Comma adds a space, resulting in 'The square is 25' (two spaces).
- ✗
Change to: print("The square is " + (num ** 2))
Why it's wrong here
Parentheses don't change the type; still concatenating int to string.
Go deeper
Related to this question
About these practice questions
One of 498 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 →
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.