Created
May 21, 2019 22:13
-
-
Save sumpygump/5416d2aef1dac80bfbc6c2c3c92423e0 to your computer and use it in GitHub Desktop.
Katakana quiz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# coding=utf-8 | |
import random | |
vowels = ["a", "i", "u", "e", "o"] | |
predicate_consonants = ["k", "g", "s", "z", "t", "d", "n", "h", "b", "p"] | |
syllables = [] | |
_chars = "アイウエオカキクケコガギグゲゴサシスセソザジズゼゾタチツテトダヂヅデドナニヌネノハヒフヘホバビブベボパピプペポ" | |
_map = {} | |
def make_syllables(): | |
syllables = vowels.copy() | |
for c in predicate_consonants: | |
for v in vowels: | |
syl = "{}{}".format(c, v) | |
if syl == "si" : syl = "shi" | |
if syl == "zi" : syl = "ji" | |
if syl == "ti" : syl = "chi" | |
if syl == "tu" : syl = "tsu" | |
syllables.append(syl) | |
return syllables | |
def make_map(syllables, _chars): | |
return dict(zip(syllables, _chars)) | |
def make_random_word(syllables, _map): | |
wordlength = random.randint(2, 5) | |
word = {"en": "", "ja": ""} | |
for i in range(wordlength): | |
syllable = random.choice(syllables) | |
word["ja"] = word["ja"] + _map[syllable] | |
word["en"] = word["en"] + syllable | |
return word | |
def main(): | |
syllables = make_syllables() | |
_map = make_map(syllables, _chars) | |
print("Katakana quiz") | |
_user_input = "" | |
while _user_input.strip() == "": | |
word = make_random_word(syllables, _map) | |
print("Write this (made-up) word: {}".format(word["en"])) | |
_user_input = input() | |
print(" Answer: {}".format(word["ja"])) | |
print("") | |
if __name__ == "__main__": main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment