A class for notes calculation.
#!/usr/bin/env python3
from string import ascii_uppercase
class Notes:
notes = ascii_uppercase[:7]
notes_number = range(7)
notes_dict = dict(zip(notes, notes_number))
numbers_dict = dict(zip(notes_number, notes))
def __init__(self, _note):
if not _note in Notes.notes:
raise Exception("Not a valid note")
self.note = _note
self.note_number = Notes.notes_dict[self.note]
def add(self, n):
if not n in range(8):
raise Exception("Not a valid number")
old_number = Notes.notes_dict[self.note]
new_number = (old_number + n) % 7
return Notes.numbers_dict[new_number]
def minus(self, n):
if not n in range(8):
raise Exception("Not a valid number")
old_number = Notes.notes_dict[self.note]
new_number = (old_number - n) % 7
return Notes.numbers_dict[new_number]
Test:
x = Notes("G")
x.add(7)