← Back to challenges

Enharmonic Equivalents

PythonHardstringsformatting

Instructions

In music, notes can be written out in multiple ways (especially for notes on the black keys). Although these notes are spelled out differently, they still are the same note physically.

C# = Db, D# = Eb, F# = Gb, G# = Ab, A# = Bb

Given a musical note, create a function that returns its enharmonic equivalent. The examples below should make this clear.

Examples

get_equivalent("D#") ➞ "Eb"

get_equivalent("Gb") ➞ "F#"

get_equivalent("Bb") ➞"A#"

Notes

  • Note names will always be a capital letter followed by either # or b.
  • Remember that the note after G is A and vice versa.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: RegEx I: Line Anchors