← Back to challenges

Musical Instrument Note Ranges

PythonHardconditionsvalidation

Instructions

Musical instruments have a range of notes to play, some instruments having a much larger range than others.

Given the following ranges for the instrument, create a function that returns True if a given note is within a given instrument's range. Otherwise, return False.

InstrumentRange
PiccoloD4-C7
TubaD1-F4
GuitarE3-E6
PianoA0-C8
ViolinG3-A7

Examples

instrument_range("Piccolo", "A3") ➞ False

instrument_range("Violin", "G6") ➞ True

instrument_range("Piano", "C8") ➞ True

Notes

  • Tests will only include natural notes (i.e. you will only deal with letters and numbers, no special characters).
  • The musical scale follows this pattern: ... A1, B1, C1, D1, E1, F1, G1, A2, B2 ...
  • You don't need to worry about invalid inputs.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.