Courseiva
Strings →easyMultiple Choice

PCAP Strings Practice Question

Exhibit

Refer to the exhibit.

name = "Alice"
age = 30
print(f"{name} is {age} years old.")

What is the output of the code in the exhibit?

⚠ Common exam trap

Watch out — candidates often confuse f-strings with regular strings and think the literal text {name} and {age} is printed, or they may misorder the variables in the output, leading them to choose option A or D instead of recognizing the correct substitution.

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 which substitutes the values of the variables `name` and `age` into the string. Evaluating the expression results in 'Alice is 30 years old.', matching option B. Option A shows the literal braces, option C displays the variable names instead of their values, and option D reverses the order of the variables.

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 occur only if the string were written without the f prefix, making it a regular string literal where curly braces have no special meaning and are printed as-is. Since the exhibit uses an f-string (f'...'), the expressions {name} and {age} are evaluated and replaced with their values. Thus, this is not what the code actually prints.

  • ✓

    Alice is 30 years old.

    Why this is correct

    The f-string's placeholders are evaluated at runtime: {name} is replaced by the value of the variable name, which is 'Alice', and {age} is replaced by the value of age, which is 30. The resulting concatenated string matches exactly this output, making it the correct answer.

  • ✗

    name is age years old.

    Why it's wrong here

    This would be the output if the placeholders were written as literal words without curly braces, so the f-string would treat them as plain text. However, the exhibit uses {name} and {age}, which are expressions whose values ('Alice' and 30) are substituted. The variable name 'age' is not printed; its value 30 is.

  • ✗

    30 is Alice years old.

    Why it's wrong here

    The f-string processes placeholders left-to-right: {name} first, then {age}. Reversing them would produce '30 is Alice years old', but the code does not reorder the variables. The original sequence places 'Alice' before 30, so this output is impossible given the exhibit's string.

About these practice questions

This PCAP question is part of Courseiva's 421-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 →

How Courseiva writes practice questions · Editorial policy

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.