#!/usr/bin/python3

import sys
import random

# Practice with Hiragana

class BasicHiragana(object):

    def __init__(self, strlen, adaptive=False):
        """
        sets up the Hiragana we want to practice with.
        @param strlen:       how long should the challenge phrase be?
        @param adaptive:     should the challenges grow in difficulty?
        """

        self.basic_vowels = {"a" : "あ",
                             "i" : "い",
                             "u" : "う",
                             "e" : "え",
                             "o" : "お",}
        self.k_column = {"ka" : "か",
                         "ki" : "き",
                         "ku" : "く",
                         "ke" : "け",
                         "ko" : "こ",}
        self.s_column = {"sa" : "さ",
                         "shi" : "し",
                         "su" : "す",
                         "se" : "せ",
                         "so" : "そ",}

        self.all_hiragana = {}

        all_dicts = (self.basic_vowels,
                     self.k_column,
                     self.s_column,
                     )
        for dictionary in all_dicts:
            for (k, v) in dictionary.items():
                self.all_hiragana[k] = v

        self.strlen = strlen if (strlen > 0) else 13
        self.adaptive = adaptive

    def create_challenge(self):
        """
        creates and returns the random hiragana string.
        """

        strlen = self.strlen
        challenge = []
        while strlen:
            challenge.append(random.choice(tuple(self.all_hiragana.values())))
            strlen -= 1
        return "".join(challenge)

    def score_challenge(self, response, challenge):
        """
        checks the user input to see if the result is correct.
        @param response:    a space-delimited romaji string input by
                            the user.
        @param challenge:   a string in hiragana that this instance
                            generated to challenge the user.
        @return:            a tuple; the integer score and the hiragana
                            conversion of the response.
        """

        response_h_list = []
        try:
            for romaji in response.split():
                response_h_list.append(self.all_hiragana[romaji])
        except KeyError:
            return (0, "")
        response_h = "".join(response_h_list)
        if response_h == challenge:
            return (len(challenge), response_h)
        return (0, response_h)

    def collect_input(self):
        """
        collects one line of user input and chomps the trailing newline.
        @return:    the collected string.
        """
        user_input = sys.stdin.readline()
        return user_input[:-1]

    def main(self):
        """
        the main routine in which the game runs.
        """
        running_score = 0
        while True:
            challenge = self.create_challenge()
            print(challenge)

            response = self.collect_input()
            (score, response_h) = self.score_challenge(response, challenge)
            if score:
                running_score += score
            else:
                print("KABOOM! Your final score was %d." % (running_score,))
                print("You erred thus:\n%s" % (response_h,))
                return 0


if __name__ == "__main__":
    game = BasicHiragana(5)
    sys.exit(game.main())

@@ -937,16 +937,576 @@
  : %22%E3%81%9D%22,%7D
+%0A        self.t_column = %7B%22ta%22 : %22%E3%81%9F%22,%0A                         %22chi%22 : %22%E3%81%A1%22,%0A                         %22tsu%22 : %22%E3%81%A4%22,%0A                         %22te%22 : %22%E3%81%A6%22,%0A                         %22to%22 : %22%E3%81%A8%22,%7D%0A        self.n_column = %7B%22na%22 : %22%E3%81%AA%22,%0A                         %22ni%22 : %22%E3%81%AB%22,%0A                         %22nu%22 : %22%E3%81%AC%22,%0A                         %22ne%22 : %22%E3%81%AD%22,%0A                         %22no%22 : %22%E3%81%AE%22,%7D%0A        self.h_column = %7B%22ha%22 : %22%E3%81%AF%22,%0A                         %22hi%22 : %22%E3%81%B2%22,%0A                         %22fu%22 : %22%E3%81%B5%22,%0A                         %22he%22 : %22%E3%81%B8%22,%0A                         %22ho%22 : %22%E3%81%BB%22,%7D
 %0A%0A      
@@ -1635,32 +1635,140 @@
  self.s_column,%0A
+                     self.t_column,%0A                     self.n_column,%0A                     self.h_column,%0A
                 
@@ -4060,9 +4060,9 @@
 ana(
-5
+1
 )%0A  

add t,n,h columns.