Created
December 13, 2016 05:22
-
-
Save vilmibm/b677a6f1b35ca0d3a798d2fa2d7da109 to your computer and use it in GitHub Desktop.
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 | |
"""hiragana.py, by ~vilmibm. this is a little flash card script for the | |
hiragana alphabet, which i've been learning. maybe i'll have a katakana and | |
kanji flashcard quizzer soon, too ^_^""" | |
from random import choice | |
import sys | |
PAIRS = ( | |
('あ', 'a'), ('い', 'i'), ('う', 'u'), ('え', 'e'), ('お', 'o'), | |
('か', 'ka'), ('き', 'ki'), ('く', 'ku'), ('け', 'ke'), ('こ', 'ko'), | |
('が', 'ga'), ('ぎ', 'gi'), ('ぐ', 'gu'), ('げ', 'ge'), ('ご', 'go'), | |
('た', 'ta'), ('ち', 'chi'), ('つ', 'tsu'), ('て', 'te'), ('と', 'to'), | |
('だ', 'da'), ('で', 'de'), ('ど', 'do'), ('さ', 'sa'), ('し', 'shi'), | |
('す', 'su'), ('せ', 'se'), ('そ', 'so'), ('ざ', 'za'), ('じ', 'ji'), | |
('ず', 'zu'), ('ぜ', 'ze'), ('ぞ', 'zo'), ('は', 'ha'), ('ひ', 'hi'), | |
('ふ', 'fu'), ('へ', 'he'), ('ほ', 'ho'), ('ば', 'ba'), ('び', 'bi'), | |
('ぶ', 'bu'), ('べ', 'be'), ('ぼ', 'bo'), ('ぱ', 'pa'), ('ぴ', 'pi'), | |
('ぷ', 'pu'), ('ぺ', 'pe'), ('ぽ', 'po'), ('な', 'na'), ('に', 'ni'), | |
('ぬ', 'nu'), ('ね', 'ne'), ('の', 'no'), ('ま', 'ma'), ('み', 'mi'), | |
('む', 'mu'), ('め', 'me'), ('も', 'mo'), ('ら', 'ra'), ('り', 'ri'), | |
('る', 'ru'), ('れ', 're'), ('ろ', 'ro'), ('や', 'ya'), ('よ', 'yo'), | |
('ゆ', 'yu'), ('わ', 'wa'), ('を', 'oo'), ('ん', 'n') | |
) | |
QUIT_CHAR = 'q' | |
INTRO = """welcome to hiragana practice! for each printed character, type its romanji version. | |
enter {} to quit.""".format(QUIT_CHAR) | |
FINAL_REPORT = """you're awesome for working on this! you got {}% right.""" | |
def final_report(num_correct, rounds): | |
if rounds == 0: | |
return 'see ya~' | |
score = int((num_correct / rounds) * 100) | |
return FINAL_REPORT.format(score) | |
def main(): | |
num_correct = 0 | |
rounds = 0 | |
print(INTRO) | |
quitting = False | |
while not quitting: | |
challenge, answer = choice(PAIRS) | |
response = input('{} > '.format(challenge)).rstrip() | |
if QUIT_CHAR == response: | |
print(final_report(num_correct, rounds)) | |
break | |
rounds += 1 | |
if answer == response: | |
num_correct += 1 | |
print('すごい! {}/{}'.format(num_correct, rounds)) | |
else: | |
print('いいえ. {}/{}'.format(num_correct, rounds)) | |
return 0 | |
if __name__ == '__main__': | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment