← Back to challenges

Nearest Vowel

PythonHardstringsloops

Instructions

Given a letter, created a function which returns the nearest vowel to the letter. If two vowels are equidistant to the given letter, return the earlier vowel.

Examples

nearest_vowel("b") ➞ "a"

nearest_vowel("s") ➞ "u"

nearest_vowel("c") ➞ "a"

nearest_vowel("i") ➞ "i"

Notes

  • All letters will be given in lowercase.
  • There will be no alphabet wrapping involved, meaning the closest vowel to "z" should return "u", not "a".
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.