0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

pythonで自己登録制の英和辞書&テスト作ってみた

Posted at

jsonファイルはそっちで用意しないとダメかもです。(すみません)
import json
import random
import sys

while True:
select=int(input("1:登録 2:内容確認 3:削除 4:テスト 5:終了"))
if select==1:
print("終了時quitを入力してね")
while True:
eng=input("英語は?")
if eng=="quit":
break
jap=input("日本語は?")
if jap=="quit":
break
with open("english.json","r") as fp:
dic=json.load(fp)
dic[eng]=jap
with open("english.json","w") as fp:
json.dump(dic,fp)

if select==2:
    with open("english.json","r") as fp:
        r=json.load(fp)
        print("現在登録されているのは"+str(r)+"です")

if select==3:
    del_eng=input("消したい英語を入力してね")
    with open("english.json","r") as fp:
        dic_del=json.load(fp)
        del dic_del[del_eng]
    with open("english.json","w") as fp:
        json.dump(dic_del,fp)

if select==4:
    print("終了時quitを入力してね")
    while True:
        with open("english.json","r") as fp:
            dic=json.load(fp)
        que=random.choice(list(dic.keys()))
        print(que)
        command=input("日本語を表示")
        if command=="quit":
            break
        print(dic[que])

if select==5:
    sys.exit()
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?