Skip to content

S2Q2 · Uppercase Only Vowels

⚡ Quick Reference

Type: Full I/O - multiline string processing

Core idea: for each character - if it's a vowel uppercase it, otherwise lowercase it.

n = int(input())
vowels = "aeiouAEIOU"
for _ in range(n):
    line = input()
    print("".join(c.upper() if c in vowels else c.lower() for c in line))

Key rules: - Vowels → uppercase (c.upper()) - Everything else → lowercase (c.lower()) - Non-alphabetic chars: .lower() on a space or digit returns it unchanged


Problem Statement

Problem (I/O type)

Read n lines. For each line, convert vowels to uppercase and all other characters to lowercase. Print the result.

Example:

Input
2
Hello World
Python Programming
Output
hEllO wOrld
pythOn prOgrAmmIng

Tracing "Hello World"

Char Vowel? Output
H h
e E
l l
l l
o O
W w
o O
r r
l l
d d

Result: hEllO wOrld

c.lower() on non-alphabetic characters

Calling .lower() on a space, digit, or punctuation character returns it unchanged - Python's str.lower() only affects cased characters. So the else c.lower() branch safely handles all non-vowel characters including spaces.


Solution approaches

n = int(input())
vowels = "aeiouAEIOU"
for _ in range(n):
    line = input()
    print("".join(c.upper() if c in vowels else c.lower() for c in line))
n = int(input())
vowels = "aeiouAEIOU"
for _ in range(n):
    line = input()
    result = ""
    for c in line:
        if c in vowels:
            result += c.upper()
        else:
            result += c.lower()
    print(result)
import string

n = int(input())
vowels_lower = "aeiou"
vowels_upper = "AEIOU"
consonants_upper = "".join(c for c in string.ascii_uppercase if c not in vowels_upper)
consonants_lower = consonants_upper.lower()

# Map: upper vowels stay upper, lower vowels go upper,
#       upper consonants go lower, lower consonants stay lower
table = str.maketrans(
    vowels_lower + consonants_upper,
    vowels_upper + consonants_lower
)

for _ in range(n):
    print(input().translate(table))

Builds a full translation table mapping all relevant characters. Efficient for large inputs.

n = int(input())
vowels = "aeiouAEIOU"
transform = lambda c: c.upper() if c in vowels else c.lower()
for _ in range(n):
    print("".join(map(transform, input())))

map(transform, line) applies the lambda to every character. "".join(...) reassembles.


Key takeaways

01

c.upper() if c in vowels else c.lower()

The one-line decision for each character. Checking membership in a string of vowels is simple and readable - no need for a set unless the input is very large.

02

Include both cases in vowel string

"aeiouAEIOU" handles both `'e'` and `'E'` in one check. Alternatively, normalise with c.lower() in "aeiou" - either works.

03

Process line by line - no buffering

Each line can be processed and printed immediately after reading. No need to collect all lines first - keeps memory usage minimal.