← Back to challenges

First N Vowels

PythonHardstringsregexloops

Instructions

Write a function that returns the first n vowels of a string.

Examples

first_n_vowels("sharpening skills", 3) ➞ "aei"

first_n_vowels("major league", 5) ➞ "aoeau"

first_n_vowels("hostess", 5) ➞ "invalid"

Notes

  • Return "invalid" if the n exceeds the number of vowels in a string.
  • Vowels are: a, e, i, o, u
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Percentage of Box Filled In