import os
import sys
import pickle
open_sound = True
def can_be_save(local_path, filename):
for name in os.listdir(local_path):
if name == filename:
return False
return True
def say(text):
if open_sound:
os.system(“say -v%s%s” % (“Kate”, text))
if not open_sound:
pass
def cls():
os.system(“clear”)
return
while True:
rightlist = []
wronglist = []
words = {}
cmd = input(
“Which mode do you want to choicenW – Write ModenT – Test ModenS – Spell Check ModenL – Listening ModenC – Check FilenamenO – Open a file and check inside.n”).upper()
if cmd not in [“W”, “T”, “S”, “L”, “C”, “O”]:
input(“Error with mode type!”)
cls()
continue
if cmd == “W”:
while True:
try:
wordEn = input(“Input English of this word: “)
if wordEn == “EXIT”:
cmd = input(“Are you sure you want to EXITY/N)”).upper()
if cmd == “Y”:
break
wordZh = input(“Input Chinese of this word: “)
if wordEn == “EXIT” or wordZh == “EXIT”:
cmd = input(“Are you sure you want to EXITY/N)”).upper()
if cmd == “Y”:
break
print(“”)
words[wordEn] = wordZh
except KeyboardInterrupt:
break
asker = input(“Do you want to save thisY/N)”).upper()
if asker == “Y”:
while True:
try:
path = input(“Input path:”)
os.chdir(path)
break
except:
print(“Error with path!nPlease re-input!n”)
os.chdir(path)
print(“Now Working At:”, os.getcwd())
cmd = input(“Go on(Y/N)”).upper()
if cmd == “N”:
sys.exit()
if cmd == “Y”:
pass
while True:
filename = input(“Input filename: “)
if can_be_save(os.getcwd(), filename):
writefile = open(filename, “wb+”)
pickle.dump(words, writefile)
writefile.close()
break
if not can_be_save(os.getcwd(), filename):
print(“Cannot be save!”)
if asker == “N”:
sys.exit()
if cmd == “T”:
print(“Please read the file first.”)
filename = input(“Input filename: “).replace(” “, “”)
try:
loadfile = open(filename, “rb”)
words = pickle.load(loadfile)
loadfile.close()
except FileNotFoundError:
try:
loadfile = open(filename, “rb”)
words = pickle.load(loadfile)
loadfile.close()
except FileNotFoundError:
print(“File not found!”)
except PermissionError:
print(“Not allowed read this file.”)
except:
print(“Unknown Error!”)
score = 0
for name in words.keys():
wordEn = name
wordZh = words[wordEn]
print(wordEn)
try:
say(wordEn)
except:
pass
inputWordZh = input(“Input Chinese of this word: “)
if inputWordZh != “”:
if inputWordZh == wordZh or inputWordZh in wordZh:
score += 1
rightlist.append(inputWordZh)
print(“You are right.”)
print(“”)
elif inputWordZh != wordZh:
wronglist.append(inputWordZh)
print(“There are some wrong.”)
print(“”)
if inputWordZh == “”:
textwillappend = wordZh + “_IS_EMPTY”
wronglist.append(textwillappend)
print(“There are some wrong.”)
print(“”)
questions = len(words)
ticks = score
wrongs = questions – score
if ticks / questions * 100 == int(ticks / questions * 100):
ticks_percent = str(int(ticks / questions * 100)) + “%”
if ticks / questions * 100 != int(ticks / questions * 100):
ticks_percent = str(ticks / questions * 100) + “%”
if wrongs / questions * 100 == int(wrongs / questions * 100):
wrongs_percent = str(int(wrongs / questions * 100)) + “%”
if wrongs / questions * 100 != int(wrongs / questions * 100):
wrongs_percent = str(wrongs / questions * 100) + “%”
print(“Questions:”, questions, “Ticks:”, score, “Wrongs:”, wrongs, “nTicks percent:”, ticks_percent,
“nWrongs percent:”, wrongs_percent)
print(“Wrong List:”)
print(wronglist)
print(“Right List:”)
print(rightlist)
if cmd == “S”:
filename = input(“Input filename:”)
try:
loadfile = open(filename, “rb”)
words = pickle.load(loadfile)
loadfile.close()
except FileNotFoundError:
print(“File Not Found.”)
except PermissionError:
print(“Not allowed read this file.”)
except:
print(“Unknown Error!”)
score = 0
for name in words.keys():
wordEn = name
wordZh = words[wordEn]
print(wordZh)
try:
say(wordEn)
except:
pass
inputWordEn = input(“Input English of this word: “)
if inputWordEn != “”:
if inputWordEn == wordEn:
score += 1
rightlist.append(inputWordEn)
print(“You are right.”)
print(“”)
elif inputWordEn != wordEn:
wronglist.append(inputWordEn)
print(“There are some wrong.”)
print(“”)
if inputWordEn == “”:
textwillappend = wordEn + “_IS_EMPTY”
wronglist.append(textwillappend)
print(“There are some wrong.”)
print(“”)
print(“Questions:”, str(len(words)), “Ticks:”, str(score), “Wrongs:”, str(len(words) – score))
print(“Wrong List:”)
print(wronglist)
print(“Right List:”)
print(rightlist)
if cmd == “L”:
filename = input(“Input filename:”)
try:
loadfile = open(filename, “rb”)
words = pickle.load(loadfile)
loadfile.close()
except FileNotFoundError:
print(“File Not Found.”)
except PermissionError:
print(“Not allowed read this file.”)
except:
print(“Unknown Error!”)
score = 0
for name in words.keys():
wordEn = name
try:
while True:
print(wordEn)
print(words[wordEn])
print(“”)
say(wordEn)
command = input(“RepeatY/N/clear)n”)
if command == “N”:
break
if command == “clear”:
os.system(“clear”)
except:
print(“This is executable binary edition.nCannot use this.n”)
break
if cmd == “O”:
filename = input(“Filename: “)
try:
readfile = open(filename, “rb”)
words = pickle.load(readfile)
readfile.close()
for key in words.keys():
print(key, words[key])
except PermissionError:
print(“Permission Error!”)
except FileNotFoundError:
print(“File Not Found!”)
except:
print(“Unknown Error!”)
if cmd == “C”:
while True:
path = input(“Input path:”)
try:
os.chdir(path)
break
except:
print(“Error with the path you want to find!”)
filename = input(“Filename:”)
found = False
for each in os.listdir(os.getcwd()):
if each == filename:
print(“File find.”)
found = True
if not found:
print(“File not found.”)
cmd1 = input(“Stay in softwareY/N)”).upper()
cmd2 = input(“ClearY/N)”).upper()
if cmd2 == “Y”:
os.system(“clear”)
if cmd1 == “Y”:
pass
if cmd1 == “N”:
break
文章知识点与官方知识档案匹配,可进一步学习相关知识Python入门技能树首页概览208940 人正在系统学习中 相关资源:下拉通刷词软件v3.1.zip-其它代码类资源-CSDN文库
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!