Skip to content

Instantly share code, notes, and snippets.

@mpobrien
Created November 10, 2015 23:10
Show Gist options
  • Save mpobrien/7ef6d1a3a23da3ef8c5c to your computer and use it in GitHub Desktop.
Save mpobrien/7ef6d1a3a23da3ef8c5c to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import random
from termcolor import colored
hiragana = [
[['a', 'あ'], ['i', 'い'], ['u', 'う'], ['e', 'え'], ['o', 'お']],
[['ka', 'か'], ['ki', 'き'], ['ku', 'く'], ['ke', 'け'], ['ko', 'こ']],
[['sa', 'さ'], ['shi', 'し'], ['su', 'す'], ['se', 'せ'], ['so', 'そ']],
[['ta', 'た'], ['chi', 'ち'], ['tsu', 'つ'], ['te', 'て'], ['to', 'と']],
[['na', 'な'], ['ni', 'に'], ['nu', 'ぬ'], ['ne', 'ね'], ['no', 'の']],
[['ha', 'は'], ['hi', 'ひ'], ['fu', 'ふ'], ['he', 'へ'], ['ho', 'ほ']],
[['ma', 'ま'], ['mi', 'み'], ['mu', 'む'], ['me', 'め'], ['mo', 'も']],
[['ya', 'や'], ['yu', 'ゆ'], ['yo', 'よ']],
[['ra', 'ら'], ['ri', 'り'], ['ru', 'る'], ['re', 'れ'], ['ro', 'ろ']],
[['wa', 'わ'], ['o', 'を']],
[['n', 'ん']],
[['ga', 'が'], ['gi', 'ぎ'], ['gu', 'ぐ'], ['ge', 'げ'], ['go', 'ご']],
[['za', 'ざ'], ['ji', 'じ'], ['zu', 'ず'], ['ze', 'ぜ'], ['zo', 'ぞ']],
[['da', 'だ'], ['ji', 'ぢ'], ['zu', 'づ'], ['de', 'で'], ['do', 'ど']],
[['ba', 'ば'], ['bi', 'び'], ['bu', 'ぶ'], ['be', 'べ'], ['bo', 'ぼ']],
[['pa', 'ぱ'], ['pi', 'ぴ'], ['pu', 'ぷ'], ['pe', 'ぺ'], ['po', 'ぽ']],
];
active = set([0,1])
minlen = 1
maxlen = 4
def generate_word(length):
x = []
active_classes = [hiragana[i] for i in xrange(0, len(hiragana)) if i in active]
while len(x) < length:
syl_class = random.choice(active_classes)
x.append(random.choice(syl_class))
return x
def main():
while True:
new_word = generate_word(maxlen)
jap = ''.join(x[1] for x in new_word)
eng = ''.join(x[0] for x in new_word)
print jap,
test = raw_input()
if test.strip() == eng:
print colored('RIGHT!', 'green')
print ''
else:
print colored('Wrong!', 'red')
print eng
raw_input()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment