Please write a program which asks the user to type in some text. Your program should then perform a spell check, and print out feedback to the user, so that all misspelled words have stars around them. Please see the two examples below:
Write text: We use ptython to make a spell checker
We use *ptython* to make a spell checker
wordlist.txt 包含了所有单词。
一些需要注意的点:
1. 需要统一成小写。
2. split()的使用可以成功把一句话中的内容切成了单词,并转换为数组。
3. ‘’.join([a,b])的使用,成功把ab字符串相连,若更换ab顺序,则是在b后连a.
text = input("Write text: ")
words = text.split()
with open("wordlist.txt") as new_file:
wordlis = []
for item in new_file:
wordlis.append(item.strip())
adj = []
for i in range(len(words)):
if words[i].lower() in wordlis:
adj.append(words[i])
continue
else:
c = "*"
words[i] =''.join([c,words[i]])
words[i] =''.join([words[i],c])
adj.append(words[i])
for w in adj:
print(w,end=" ")
题目来源:Helsinki, part 6, spell checker



