35
\$\begingroup\$

Challenge

You will be given a string that can contain lowercase letters, uppercase letters, or spaces. You have to turn the vowels (a, e, i, o, u) in the string to upper case and consonants to lower case. This applies whether or not the letter was originally upper case or lower case. Spaces remain as is. Note that "y" is a consonant.

Examples

Hello World -> hEllO wOrld
abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVXWYZ -> AbcdEfghIjklmnOpqrstUvwxyz AbcdEfghIjklmnOpqrstUvxwyz

Info

  • The input string can contain letters A to Z, lowercase or uppercase, and spaces.

Input

The string

Output

The formatted string (Vowels uppercase and consonants lowercase).

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Why on many challenges is "y" counted as a consonant ? \$\endgroup\$
    – CreaZyp154
    Feb 16, 2022 at 13:40
  • \$\begingroup\$ Because it is a consonant. (<pedantic> unless you're using international phonetic alphabet, where it's the front-high-rounded vowel /y/</pedantic>) \$\endgroup\$
    – bigyihsuan
    Feb 16, 2022 at 15:35
  • \$\begingroup\$ @bigyihsuan It's a bit more complicated than that. Wikipedia says: "In the English writing system, it mostly represents a vowel and seldom a consonant." As a child, I was taught that the vowels were "A, E, I, O, U, and sometimes Y," which could lead to viewing Y as "not really a vowel" because it's not always a vowel. Y is also a consonant in some very common words like "yes" and "you." But these are just guesses; I'm not entirely sure why Y is often not considered a vowel in coding challenges. \$\endgroup\$
    – DLosc
    Feb 16, 2022 at 18:44

62 Answers 62

1 2
3
0
\$\begingroup\$

YASEPL, 155 147 145 140 bytes

=f=2)"aeiouAEIOU"=1'=i=l®1`1=k=f=m¥i,1`9!y¥f,2!m}7,y,8!k$`8!+}2,10,9=j`2!j+!q$j»}7,m,2`3!j}1,90,5}2,65,5!$j+32|6`5!$j`6!k[7!-32`7!›!i+}2,l
\$\endgroup\$
-1
\$\begingroup\$

Python 3, 82 bytes

f=lambda c:c.upper()if c in 'aeiou'else c.lower();lambda s:''.join(map(f,list(s)))
\$\endgroup\$
1 2
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.