因此,基本上我有一個文本文件中的單詞列表,我希望能夠搜索匹配的單詞時用戶輸入一個檢查拼寫,這是到目前爲止,我有什麼。在python中搜索文本文件中的輸入詞
f = open('words.txt', 'r')
wordCheck = input("please enter the word you would like to check the spelling of: ")
for line in f:
if 'wordCheck' == line:
print ('That is the correct spelling for '+wordCheck)
else:
print (wordCheck+ " is not in our dictionary")
break
當我輸入一個單詞時,我只是馬上得到else語句,我不認爲它甚至通過文本文件讀取。 我應該使用while循環嗎?
while wordCheck != line in f
我是新來的蟒蛇,最終我希望用戶能夠輸入的詞,如果拼寫不正確,程序應該打印出匹配的單詞列表(字母或以上的75%匹配)。
任何幫助,將不勝感激
爲什麼你的代碼中有'break'? – neelsg