私の小さないとこが勉強するために使用する Python ベースの語彙チェッカーを作成しようとしています。プログラムの目的は単語を表示することであり、定義を入力してチェックする必要があります。これを行う最善の方法は配列リストを使用することかどうか疑問に思っていました:
vocab = ['Python','OSX']
definition = ['programming language','operating system']
これが最善の方法ですか?もしそうなら、どうすればプログラムに語彙をランダムに表示させ、定義をチェックさせることができますか。どんな助けでも大歓迎です。君たちありがとう。
Ok。これが私がこれまでに持っているものです.... #ロシア語翻訳プログラム
import os
import random
#Asks users if they want to add more vocabulary
word_adder=raw_input("Add more words? If yes, press 1: ")
with open("Russian_study.txt","a") as f:
while word_adder=="1":
word=raw_input("Enter word: ")
translation=raw_input("Word translation: ")
f.write("'{0}':{1},".format(word,translation))
word_adder=raw_input("Add another word? If yes, press 1: ")
#Checks to see if file exists, if not one is created
with open("Russian_study.txt","a") as f:
pass
os.system('clear')
print("Begin Quiz")
#Begin testing user
with open("Russian_study.txt","r") as f:
from random import choice
question = choice(list(f))
result = raw_input('{0} is '.format(question))
print('Correct' if result==f[question] else ':(')
ただし、私の出力は
Begin Quiz
'Один':'One', is
Один のみを表示し、ユーザー入力を 1 つに対してチェックするにはどうすればよいですか?