PCAP Strings Practice Question
Exhibit
Refer to the exhibit.
```
name = "Alice"
age = 30
print(f"{name} is {age} years old.")
```What is the output?
⚠ Common exam trap
Python Institute often tests whether candidates recognize that f-strings require the `f` prefix and that all placeholders are replaced with variable values, not left as literal text — the trap here is confusing an f-string with a regular string or forgetting that the period is part of the output.
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
✓
Alice is 30 years old.
The code uses an f-string (formatted string literal) with `f"{name} is {age} years old."`. When `name = 'Alice'` and `age = 30`, the placeholders `{name}` and `{age}` are replaced by their values, producing the string `'Alice is 30 years old.'`. The trailing period is part of the string literal, so it appears in the output.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
{name} is {age} years old.
Why it's wrong here
This output would be produced if the statement used a plain string literal without the f prefix, for example print("{name} is {age} years old."). In a non-f string, curly braces have no special meaning, so Python treats '{name}' and '{age}' as ordinary characters. The f prefix is what activates expression interpolation, so without it the variable names and braces are printed verbatim.
- ✓
Alice is 30 years old.
Why this is correct
Here the f-string evaluates the expressions inside the braces against the current namespace: name holds the string 'Alice' and age holds the integer 30. Each expression result is formatted and spliced directly into the surrounding literal text, giving the exact sequence 'Alice is 30 years old.' including the period. This is the correct result because the braces are not decorative; they request Python to evaluate the variable names.
- ✗
Alice is 30 years old
Why it's wrong here
The source code ends with a literal period inside the closing quote, and an f-string preserves every character that is not part of a braced expression. Removing that final character changes the output to 'Alice is 30 years old' without the punctuation. The mistake is not about how values are converted but about forgetting that static characters outside braces are copied unchanged.
- ✗
name is age years old.
Why it's wrong here
This result occurs only if no braces are present in the f-string at all, causing the words 'name' and 'age' to remain literal text. In the actual statement, the braces around name and age mark them as expressions to be evaluated, so Python substitutes their values. Treating the braces as optional or decorative would ignore the core mechanism of f-string interpolation.
Go deeper
Related to this question
About these practice questions
Courseiva writes every PCAP question from scratch — 421 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 by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This PCAP 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 PCAP exam.