#SPELL CHECK PROGRAM
def SpellCheck():
import difflib
import urllib.request
#Downloads 10000 most used english words as txt file
url = 'https://raw.githubusercontent.com/first20hours/google-10000-english/master/google-10000-english.txt'
response = urllib.request.urlopen(url)
data = response.read() #
text = data.decode('utf-8') #
x = True
while x == True:
print("Enter your word: ")
word = input(">> ")
clr(2)
s(3)
if (word.lower()) in text:
print(word, " is spelt correctly")
else:
print("It doesn't seem like i know that word")
#closewords = difflib.get_close_matches(word, text)
wrongcount = 0
correctcount = 0
closewords = []
############
for x in text:
wrongcount = 0
correctcount = 0
for let in x:
for letter in word:
if let == letter:
correctcount += 1
else:
wrongcount +=1
if correctcount > len(word) - 4:
closewords.append(x)
else:
x = 0
#############
print("Perhaps you meant one of these: ")
print(closewords)
print("Would you like to try again?")
again = input(">> ")
if again == 'Y' or again == 'y' or again == 'yes' or again == 'Yes':
x = True
else:
print("Okay")
x = False
它應該採取的10,000個最常用的英語單詞列表,並把它們變成一個列表。 如果用戶的單詞與列表中的某個單詞不匹配,它應該: 對於每個單詞中的每個字母,請檢查該單詞是否與用戶單詞中的單詞相匹配。 使用此來查看這兩個單詞中是否有任何/許多字母匹配。如果他們這樣做,將其打印在建議列表中。的Python 3:基本拼寫檢查
如果輸入的單詞拼寫正確;它會打印拼寫正確
如果輸入的單詞拼寫錯誤;它會打印出拼寫錯誤,但它不會給出任何建議,即使例如; (我輸入「pooison」,它不會拿出任何東西,即使「毒藥」是字典)
應該在這種情況下,打印出「毒藥」
問題是?它是否根本無法工作?它有什麼作用?它有任何工作嗎? – marsh 2014-11-03 12:54:19
其中一些工作,但它沒有打印出任何建議。 – 2014-11-03 13:04:42
你可以[編輯]你的問題,包括它在運行時顯示的內容和你期望的內容? – thegrinner 2014-11-03 13:12:00