Skip to content

Commit

Permalink
Add script calculate Major scale
Browse files Browse the repository at this point in the history
  • Loading branch information
hvnsweeting committed Feb 26, 2017
1 parent 6dbec46 commit c1b3631
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions Python/major_scale.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Author: [email protected]
# Tested with Python3
# python major_scale.py C
# ['C', 'D', 'E', 'F', 'G', 'A', 'B', 'C']

import argparse

__doc__ = '''Script prints out major scale start from input note.'''

notes = ('A', 'Bb', 'B', 'C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab')
noteno = len(notes)
WHOLE = 2
HALF = 1


def next_steps(note, steps=HALF):
idx = notes.index(note)
for step in range(steps):
idx = (idx + 1) % noteno
return notes[idx]


def major_scale(start):
out = []
out.append(start)
n = start
for step in [WHOLE, WHOLE, HALF, WHOLE, WHOLE, WHOLE, HALF]:
n = next_steps(n, step)
out.append(n)

return out


def main():
argp = argparse.ArgumentParser()
argp.add_argument('note', help='Note starts the major scale')
args = argp.parse_args()
print(major_scale(args.note))


if __name__ == "__main__":
main()

0 comments on commit c1b3631

Please sign in to comment.