Last active
August 29, 2015 14:17
-
-
Save Echocage/4f1e0d377ed6a0ded073 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
import random | |
JAPANESE_CHARACTERS = [ | |
['いちまい', 'にまい', 'さんまい', 'よんまい', 'ごまい', 'ろくまい', 'ななまい', 'はちまい', 'きゅうまい', 'じゅうまい'], | |
['いっさつ', 'にさつ', 'さんさつ', 'よんさつ', 'ごさつ', 'ろくさつ', 'ななさつ', 'はっさつ', 'きゅうさつ', 'じゅさつ'], | |
['いっぽん', 'にほん', 'さんぼん', 'よんまい', 'ごまい', 'ろくまい', 'ななまい', 'はちまい', 'きゅうまい', 'じゅうまい'], | |
['ひとつ', 'ふたつ', 'みっつ', 'よっつ', 'いつつ', 'むっつ', 'ななつ', 'やっつ', 'ここのつ', 'とお'] | |
] | |
answer_selections = ["a", "b", "c", "d"] | |
def get_answers(real_answer_num): | |
fake_answers = set() | |
while len(fake_answers) < 3: | |
rand_num = random.randrange(1, 10) | |
if rand_num != real_answer_num: | |
fake_answers.add(rand_num) | |
fake_answers.add(real_answer_num) | |
return list(fake_answers) | |
def allow_guesses(num, character): | |
for chance in range(3): | |
print('Guess', chance) | |
fake_answers = get_answers(num) | |
print(character) | |
choices_prompt = ['{}) {}'.format(letter, answer) for letter, answer in zip(answer_selections, fake_answers)] | |
print('\n'.join(choices_prompt)) | |
response = input('>') | |
if answer_selections.index(response) + 1 == num: | |
return True | |
def quiz_from_set(choice): | |
characters = list(enumerate(JAPANESE_CHARACTERS[choice])) | |
random.shuffle(characters) | |
for answer_num, character in characters: | |
is_correct = allow_guesses(answer_num, character) | |
print('Correct' if is_correct else ('Wrong! The answer was ' + str(answer_num))) | |
catagories = ('Flat-thin objects', 'Bound volume', 'Slender-thin objects', 'General counter') | |
selection_menu = '\n'.join(['{}.{}'.format(index + 1, catagory) for index, catagory in enumerate(catagories)]) | |
while True: | |
response = input("What do you want to study?\n" + selection_menu + '\n>') | |
if not response: | |
break | |
if response.isnumeric() and 0 < int(response) < 5: | |
choice = int(response) - 1 | |
print('loading', catagories[choice]) | |
quiz_from_set(choice) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment