-
Notifications
You must be signed in to change notification settings - Fork 0
/
keysigquestion.py
49 lines (38 loc) · 1.4 KB
/
keysigquestion.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import random
from key import Key
PY2 = (str is bytes)
if PY2:
my_input = raw_input
else:
my_input = input
class KeySigQuestion(object):
def __init__(self, aKey=None):
if aKey is None:
self.itsKey = Key()
else:
self.itsKey = Key(aKey)
self.majorKeyName = self.itsKey.key[0]
def ask(self):
choice = []
choice.append(self.givenKeyGiveAccidentals)
choice.append(self.givenSignatureGiveKey)
choice.append(self.givenAccidentalsGiveKey)
return random.choice(choice)()
def givenKeyGiveAccidentals(self):
self.q = "What's the key signature of " + self.majorKeyName + "? "
self.correctAns = self.itsKey.textual_key_signature()
self.a = my_input(self.q).strip()
result = (self.a == self.correctAns)
return result
def givenSignatureGiveKey(self):
self.q = "What key has " + self.itsKey.textual_key_signature() + "? "
self.correctAns = self.majorKeyName
self.a = my_input(self.q).strip()
result = (self.a == self.correctAns)
return result
def givenAccidentalsGiveKey(self):
self.q = "What key has " + ", ".join(self.itsKey.accidentals()) + "? "
self.correctAns = self.majorKeyName
self.a = my_input(self.q).strip()
result = (self.a == self.correctAns)
return result