+ 1586244404954
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Word_quiz/Word_quiz.py b/Word_quiz/Word_quiz.py
new file mode 100644
index 0000000..daeac1d
--- /dev/null
+++ b/Word_quiz/Word_quiz.py
@@ -0,0 +1,141 @@
+#!/usr/bin/env python
+# coding: utf-8
+
+# In[2]:
+
+
+import glob
+import random
+
+def makeVocabFile(filename, vocabDict):
+# Creates a vocabulary list in a file based on the dictionary passed.
+ fd = open(filename, "w")
+
+ for engWord in vocabDict.keys():# The file in TXT is separated by: and the back half is put in this section
+ fd.write(cnWord + ":")
+ fd.write(str(vocabDict[cnWord]).replace('[','').replace(']', '').replace("\', \'",",").replace("\'",""))
+ fd.write('\n')
+
+ fd.close()
+
+def quizQuestion(cnWord, engWords):
+ '''
+ Quizzes the user on one specific Chinese word.
+ Receives: Chinese word and a list of English words.
+ Returns: True or False, depending on if the question was answered correctly.
+ '''
+ incorrect = False
+ i = 1
+
+ print
+ print ("中文: "+ cnWord)
+ print ("输入" + str(len(engWords)) + " 相应的英文单词.")
+
+ while (len(engWords) > 0 and incorrect == False):
+ engWord = input("Word [" + str(i) + "]: ") # input your answer
+
+ if (engWord in engWords): # If your answer is right
+ engWords.remove(engWord)
+ i += 1
+ else: # If your answer is wrong
+ print ("Incorrect.")
+ print ("The correct answer is:" + engWords[0])
+ incorrect = True
+
+ if not incorrect:
+ print ("Correct!")
+
+ print
+ print ("---")
+
+ return not incorrect
+
+def createDict(filename):
+ '''
+ Loads a dictionary based on a file containing vocabulary words.
+
+ Receieves: Vocabulary file to read in.
+ Returns: Dictionary with key being Chinese word and item being list of English words.
+ '''
+ vocabDict = {}
+
+ fd = open(filename, "r", encoding='UTF-8')# Open the file and recognize the cnWord
+
+ for line in fd:
+ line = line.strip() # The number of test words in the wordlist
+
+ tokens = line.split(":")
+ cnWord = tokens[0]
+ engWords = tokens[1]
+
+ engWordList = tokens[1].split(",") # More than one answer
+
+ vocabDict[cnWord] = engWordList
+
+ fd.close()
+
+ return vocabDict
+
+def main():
+ '''
+ GUIDE:
+ 1. User chooses a vocabulary list.
+ 2. User chooses number of words in list to be quizzed on.
+ 3. Random quiz list is generated.
+ 4. User is quizzed on each word.
+ 5. If the user missed any, user given option to make a new vocab list of missed words.
+ '''
+ fileList = glob.glob("*.txt")
+
+ if len(fileList) == 0:
+ print ("There are no vocab lists available!")
+ return
+
+ print ("Welcome to the vocabulary quiz program. Select one of the following word lists:")
+
+ for file in fileList:
+ print ("\t"+ file)
+
+ filename = input("Please make your selection: ")
+
+ while filename not in fileList:
+ filename = input("Please make a valid selection: ")
+
+ vocabDict = createDict(filename)
+
+ noQs = int(input(str(len(vocabDict)) + " entries found. How many words would you like to be quizzed on? "))
+
+ # make sure we get a valid input
+ while(noQs < 1 or noQs > len(vocabDict)):
+ noQs = int(input("Invalid input. Please try again: "))
+
+ # generates a quiz by sampling without replacement
+ quizList = random.sample(vocabDict.keys(), noQs)
+
+ numCorrect = 0
+ incorrectDict = {}
+
+ # quizzes user on each word
+ for word in quizList:
+ if quizQuestion(word, vocabDict[word][:]) == True:
+ numCorrect += 1
+ else:
+ incorrectDict[word] = vocabDict[word]
+
+ print
+ str(numCorrect) + (" out of ")+ str(noQs) + (" correct.")
+
+main()
+
+
+# In[ ]:
+
+
+
+
+
+# In[ ]:
+
+
+
+
diff --git a/Word_quiz/__pycache__/test_4.cpython-37.pyc b/Word_quiz/__pycache__/test_4.cpython-37.pyc
new file mode 100644
index 0000000..51b5a21
Binary files /dev/null and b/Word_quiz/__pycache__/test_4.cpython-37.pyc differ
diff --git a/Word_quiz/chinese.txt b/Word_quiz/chinese.txt
new file mode 100644
index 0000000..18b0956
--- /dev/null
+++ b/Word_quiz/chinese.txt
@@ -0,0 +1,16 @@
+绝对的 纯粹的:absolute
+完全地 绝对地:absolutely
+吸收 使专心:absorb
+抽象的 摘要:abstract
+丰富的 大量的:abundant
+滥用 虐待 滥用:abuse
+学院的 学术的:academic
+私立中学 专科院校:academy
+加快 促进:accelerate
+加速 加速度:acceleration
+口音 腔调 重音:accent
+可接受的 合意的:acceptable
+接受 验收 承认:acceptance
+接近 通道 入口:access
+同谋 从犯 附件:accessory
+意外的 事故:accident
\ No newline at end of file
diff --git a/Word_quiz/test.py b/Word_quiz/test.py
new file mode 100644
index 0000000..700978a
--- /dev/null
+++ b/Word_quiz/test.py
@@ -0,0 +1,158 @@
+#!/usr/bin/env python
+# coding: utf-8
+
+# In[2]:
+
+
+import glob
+import random
+
+def makeVocabFile(filename, vocabDict):
+ # Creates a vocabulary list in a file based on the dictionary passed.
+ fd = open(filename, "w")
+
+ for engWord in vocabDict.keys():# The file in TXT is separated by: and the back half is put in this section
+ fd.write(cnWord + ":")
+ fd.write(str(vocabDict[cnWord]).replace('[','').replace(']', '').replace("\', \'",",").replace("\'",""))
+ fd.write('\n')
+
+ fd.close()
+
+def quizQuestion(cnWord, ans, testword):
+ '''
+ Quizzes the user on one specific Chinese word.
+
+ Receives: Chinese word and a list of English words.
+ Returns: True or False, depending on the question was answered correctly.
+ '''
+ incorrect = False
+ i = 1
+
+ print
+ print ("中文: " + cnWord)
+ print ("输入" + str(len(ans)) + " 相应的英文单词.")
+
+ while (len(ans) > 0 and incorrect == False):
+ #print the actual input and the expected input
+ print(testword)
+ print(ans)
+ # take testword and ans as sets in order to do subtraction afterwords
+ a = set(testword)
+ b = set(ans)
+ if (testword == ans):
+ # remove the answered word from the list
+ ans = list(b-a)
+ i += 1
+ else:
+ print ("Incorrect.")
+ print ("The correct answer is:" + ans[0])
+ incorrect = True
+
+ if not incorrect:
+ print("Correct!")
+
+ print
+ print ("---")
+
+
+ return not incorrect
+
+def createDict(filename):
+ '''
+ Loads a dictionary based on a file containing vocabulary words.
+
+ Receieves: Vocabulary file to read in.
+ Returns: Dictionary with key being Chinese word and item being list of English words.
+ '''
+ vocabDict = {}
+
+ fd = open(filename, "r", encoding='UTF-8')
+
+ for line in fd:
+ line = line.strip()
+
+ tokens = line.split(":")
+ cnWord = tokens[0]
+ engWords = tokens[1]
+
+ engWordList = tokens[1].split(",")
+
+ vocabDict[cnWord] = engWordList
+
+ fd.close()
+
+ return vocabDict
+
+
+def vocabTest():
+ '''
+ Loads a dictionary based on a file containing vocabulary words.
+
+ Receieves: Vocabulary file to read in.
+ Returns: Dictionary with key being Chinese word and item being list of English words.
+ '''
+ vocabTest = [] # Initiate a empty list to store the results
+ f = open('test_input0.txt', "r", encoding='UTF-8')
+ sourceInLines = f.readlines() # Read the content by lines
+ f.close()
+ for line in sourceInLines:
+ temp1 = line.strip('\n') # strip the line changing symbol '\n'
+ temp2 = temp1.split(',') # split the list by ','
+ vocabTest.append(temp2)
+ return vocabTest
+
+
+
+def main():
+ '''
+ GUIDE:
+ 1. User chooses a vocabulary list.
+ 2. The complete quiz list is generated.
+ 3. The input is tested.
+ '''
+ fileList = glob.glob("*.txt")
+
+ if len(fileList) == 0:
+ print ("There are no vocab lists available!")
+ return
+
+ print ("Welcome to the vocabulary quiz program. Select one of the following word lists:")
+
+ for file in fileList:
+ print ("\t"+ file)
+
+ filename = input("Please make your selection: ")
+
+ while filename not in fileList:
+ filename = input("Please make a valid selection: ")
+
+ vocabDict = createDict(filename)
+ #initiate a list with all the words
+ quizList = vocabDict.keys()
+
+ numCorrect = 0
+ incorrectDict = {}
+
+ #Test each word
+ inputWord = vocabTest()
+ a = 0
+
+ for word in quizList:
+ a += 1
+ if quizQuestion(word, vocabDict[word][:], inputWord[a-1]) == True:
+ numCorrect += 1
+ else:
+ incorrectDict[word] = vocabDict[word]
+
+
+ #Show the result with a given input
+ print(str(numCorrect) + (" out of 16 correct."))
+
+main()
+
+
+# In[ ]:
+
+
+
+
diff --git a/Word_quiz/test_input0.txt b/Word_quiz/test_input0.txt
new file mode 100644
index 0000000..e57d411
--- /dev/null
+++ b/Word_quiz/test_input0.txt
@@ -0,0 +1,16 @@
+absolute
+absolutely
+absorb
+abstract
+abundant
+abuse
+academic
+academy
+accelerate
+acceleration
+accent
+acceptable
+acceptance
+access
+accessory
+accident
\ No newline at end of file
diff --git a/Word_quiz/test_input1.txt b/Word_quiz/test_input1.txt
new file mode 100644
index 0000000..8326c7a
--- /dev/null
+++ b/Word_quiz/test_input1.txt
@@ -0,0 +1,16 @@
+accident
+absolute
+absolutely
+absorb
+abstract
+abundant
+abuse
+academic
+academy
+accelerate
+acceleration
+accent
+acceptable
+acceptance
+access
+accessory
diff --git a/Word_quiz/test_input2.txt b/Word_quiz/test_input2.txt
new file mode 100644
index 0000000..8c07e4e
--- /dev/null
+++ b/Word_quiz/test_input2.txt
@@ -0,0 +1,16 @@
+absolutely
+absorb
+abstract
+abundant
+abuse
+academic
+academy
+accelerate
+acceleration
+accent
+acceptable
+acceptance
+access
+accessory
+accident
+absolute
\ No newline at end of file
diff --git a/Word_quiz/test_input3.txt b/Word_quiz/test_input3.txt
new file mode 100644
index 0000000..3d61a56
--- /dev/null
+++ b/Word_quiz/test_input3.txt
@@ -0,0 +1,16 @@
+absolute
+absolutely
+absorbance
+abstract
+abundant
+abuse
+academic
+academy
+accelerate
+acceleration
+accent
+acceptable
+acceptance
+accessable
+accessory
+accidents
\ No newline at end of file
diff --git a/Word_quiz/test_input4.txt b/Word_quiz/test_input4.txt
new file mode 100644
index 0000000..a007e69
--- /dev/null
+++ b/Word_quiz/test_input4.txt
@@ -0,0 +1,16 @@
+绝对的
+absolutely
+absorb
+!@#¥%……
+abundant
+abuse
+academic
+academy
+accelerate
+acceleration
+accent
+(*……&%¥
+acceptance
+access
+accessory
+accident
\ No newline at end of file
diff --git "a/Word_quiz/\351\241\271\347\233\256\345\256\236\350\267\265\346\265\213\350\257\225\347\273\223\346\236\234.docx" "b/Word_quiz/\351\241\271\347\233\256\345\256\236\350\267\265\346\265\213\350\257\225\347\273\223\346\236\234.docx"
new file mode 100644
index 0000000..9bfbf4f
Binary files /dev/null and "b/Word_quiz/\351\241\271\347\233\256\345\256\236\350\267\265\346\265\213\350\257\225\347\273\223\346\236\234.docx" differ
diff --git a/unit2/word_count.py b/unit2/word_count.py
new file mode 100644
index 0000000..85a88a5
--- /dev/null
+++ b/unit2/word_count.py
@@ -0,0 +1,11 @@
+def word_count(fn):
+ import os.path
+ if os.path.isfile(fn):
+ with open(fn, 'r') as fh:
+ total = 0
+ for line in fh:
+ total += len(line.split())
+ return total
+ else:
+ print('file not found')
+word_count('C:\Users\lzl\Desktop\git102\SES2020spring\unit2\readme.md')
\ No newline at end of file