Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from spellchecker import *
- print('Welcome to Text File Spellchecker.')
- fileName = str(input('Enter the name of the file to read:'))
- def get_file(file):
- try:
- passed=0
- failed=0
- SP = spellchecker("english_words.txt")
- linenumber = 0
- with open (file) as f:
- lines = f.readlines()
- print()
- for line in lines:
- linenumber+=1
- words = line.split()
- for word in words:
- if SP.check(word) == False:
- print('Possible Spelling Error on line {}: {}'.format(linenumber,word))
- failed+=1
- else:
- passed+=1
- total=passed+failed
- print("{} words passed spell checker.".format(total-failed))
- print('{} words failed spell checker.'.format(failed))
- percentPassed = ((failed/total)*100)-100
- print('{:.2f}% of the words passed.'.format(abs(percentPassed)))
- except:
- print()
- print("Could not open file.")
- fileName = str(input('Enter the name of the file to read:'))
- get_file(fileName)
- get_file(fileName)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement