PCAP Strings Practice Question
A developer wants to replace all vowels in a string with their corresponding uppercase letters. They wrote: `s = 'hello world'`; `vowels = 'aeiou'`; `trans = str.maketrans(vowels, vowels.upper())`; `result = s.translate(trans)`. What is the value of `result`?
⚠ Common exam trap
Python Institute often tests the distinction between `str.maketrans()` and `str.replace()`, and the trap here is that candidates mistakenly think all letters are affected or that the mapping applies to consonants, when in fact only the specified characters (vowels) are transformed.
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
✓
'hEllO wOrld'
The `str.maketrans(vowels, vowels.upper())` creates a translation table mapping each lowercase vowel to its uppercase equivalent. The `translate()` method then replaces only the vowels in the original string, leaving all other characters unchanged. In 'hello world', the vowels 'e', 'o', 'o' become 'E', 'O', 'O', resulting in 'hEllO wOrld' — note that the first 'h' and 'w' remain lowercase because they are consonants.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
'HEllO WOrld'
Why it's wrong here
The output 'HEllO WOrld' incorrectly applies uppercase to the consonants 'h' and 'w' at the beginning of each word, even though the rule targets only vowel characters. While its vowels ('E' and 'O') are indeed uppercased, the transformation also alters non-vowel characters, so it cannot be the result of a vowel-only substitution. A correct replacement must leave every consonant exactly as it appeared in the original string.
- ✓
'hEllO wOrld'
Why this is correct
In 'hEllO wOrld', each vowel from the original 'hello world' has been changed to its uppercase counterpart: 'e' becomes 'E' and every 'o' becomes 'O' ('hello' becomes 'hEllO' and 'world' becomes 'wOrld'). All consonants ('h', 'l', 'w', 'r', 'd') remain lowercase exactly as they appeared in the input. This aligns perfectly with the requirement to replace all vowels without touching non-vowels.
- ✗
'H@ll@ W@rld'
Why it's wrong here
The string 'H@ll@ W@rld' replaces vowels with the symbol '@' instead of uppercasing them, so it fails the core transformation required. It also erroneously uppercases the leading consonants 'h' and 'w', adding unauthorized changes that are not part of any vowel-replacement rule. This output is not a case-mapped vowel substitution and would result from a fundamentally different operation.
- ✗
'hello world'
Why it's wrong here
Returning 'hello world' means no replacement occurred at all: the vowels 'e' and 'o' are still lowercase. This would be the behavior of code that never enters the replacement branch, such as checking an empty list of vowels, using the wrong character set, or assigning the string to itself without transformation. It therefore does not satisfy the explicit requirement that all vowels be replaced.
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.