I made a small command line tool to help my Italian studies. Any thoughts on how it could be improved? I can't think of much but would like to be proved wrong.
import random
class RegularVerb(object):
def __init__(self, name):
self._name = name
def name(self):
return self._name
def _make(self, verb_end):
return self.name()[:-3] + verb_end
def _build_condizionale_semplice(self, verb_forms, prefix):
def verb_base(prefix):
return (prefix + condizionale_semplice_base
for condizionale_semplice_base in
['rei', 'resti', 'rebbe', 'remmo', 'reste', 'rebbero']
)
return dict(zip(verb_forms, verb_base(prefix)))
class EreVerb(RegularVerb):
def __init__(self, name, verb_forms):
super(EreVerb, self).__init__(name)
self._condizionale_semplice = self._build_condizionale_semplice(verb_forms, 'e')
def condizionale_semplice(self, verb_form):
return self._make(self._condizionale_semplice[verb_form])
class IreVerb(RegularVerb):
def __init__(self, name, verb_forms):
super(IreVerb, self).__init__(name)
self._condizionale_semplice = self._build_condizionale_semplice(verb_forms, 'i')
def condizionale_semplice(self, verb_form):
return self._make(self._condizionale_semplice[verb_form])
class AreVerb(RegularVerb):
def __init__(self, name, verb_forms):
super(AreVerb, self).__init__(name)
self._condizionale_semplice = self._build_condizionale_semplice(verb_forms, 'e')
def condizionale_semplice(self, verb_form):
return self._make(self._condizionale_semplice[verb_form])
class Questioner():
def __init__(self, verb_forms, verbs):
self._verb_forms = verb_forms
self._verbs = verbs
def _handle_answer(self, user_answer, correct_answer):
if user_answer == correct_answer:
print "bravo!"
else:
print "no, correct form is:", correct_answer
def ask_random_condizionale_semplice(self):
def ask(verb_form, verb):
print "condizionale semplice for {0} in {1}?".format(verb.name(), verb_form),
self._handle_answer(raw_input(), verb.condizionale_semplice(verb_form))
ask(random.choice(self._verb_forms), random.choice(self._verbs))
def build_regular_verbs(verbs, verb_forms):
def make(verb):
if verb[-3:] == 'are':
return AreVerb(verb, verb_forms)
elif verb[-3:] == 'ire':
return IreVerb(verb, verb_forms)
elif verb[-3:] == 'ere':
return EreVerb(verb, verb_forms)
else:
raise Exception("not a regular verb")
return [make(v) for v in verbs]
def build_questioner(verb_forms, regular_verbs):
return Questioner(verb_forms,
build_regular_verbs(
regular_verbs,
verb_forms
)
)
if __name__ == "__main__":
questioner = build_questioner(
['I sg', 'II sg', 'III sg', 'I pl', 'II pl', 'III pl'],
['passare', 'mettere', 'sentire'],
)
while True:
questioner.ask_random_condizionale_semplice()