Proper function layout, calling browsing

• posted
0

Trying to build a 3 function program:

1. What key(music)?
2. Major or minor?
3.What level (for practicing)?
Having trouble with local variables I think. The steps should be: get the key, decide between major or minor scales, then determine how many scales to provide, 1, 2, or 3?
I have this working properly without functions but believe there’s a cleaner way to write it.
from random import choice

def key():
keys = ['A','B','C','D','E','F','G']
k1=input('Choose your key: ').upper()
if k1 in keys:
print('Ahh,',k1, 'excellent choice.')
else:
print('I do not understand your choice.')

key()

def tone():
major = ['Ionian: W,W,H,W,W,W,H','Lydian: W,W,W,H,W,W,H','Mixolydian: W,W,H,W,W,H']
minor= ['Dorian: W,H,W,W,W,H,W','Phrygian: H,W,W,W,H,W,W','Aeolian: W,H,W,W,H,W,W','Locrian: H,W,W,H,W,W,W','Harmonic Minor: W,H,W,W,H,W+H,H']
ask2 = input('Major or Minor: ')
question = choice(major)

question = choice(minor)

def level():
ask = int(input('Choose your level(1, 2, or 3): '))
if (ask == 1):
question = choice()
elif (ask == 2):
question = choice(),choice()
elif (ask == 3):
question = choice(),choice(),choice()
else:
print('I do not understand your choice.')

level()
tone()

• posted
0

It would be cleaner if those functions returned the answer, or raise an exception, e.g:

selected_key=key()
selected_tone=tone()
selected_level=level()

level() probably should not be an embedded function, but should live at the same level as key() and tone()

Internal error.

Oops! Looks like something went wrong!