# L-11 MCS 275 Fri 3 Feb 2017 : enumwstop.py
"""
Enumerates all combinations of letters
with interactive stop condition.
"""

def ask_to_continue(word):
    """
    Shows the string word and then asks
    the user to continue or not.
    """
    qst = 'the word is \"' + word + '\"'
    qst = qst + ' continue ? (y/n) '
    ans = input(qst)
    return ans == 'y'

def enumwords(k, letters, accu):
    """
    Starting with the k-th list in letters,
    adds letters to the current string accu,
    returns a boolean: to continue or not.
    """
    if k >= len(letters):
        return ask_to_continue(accu)
    else:
        for letter in letters[k]:
            cont = enumwords(k+1, letters, accu+letter)
            if not cont:
                break
        return cont

def main():
    """
    enumerates letter combinations
    """
    csv = ['c', 's', 'v']
    vowels = ['a', 'e', 'i', 'o', 'u']
    dtw = ['d', 't', 'w']
    let = [csv, vowels, dtw]
    enumwords(0, let, '')

if __name__ == "__main__":
    main()
