Advertisement
Guest User

Untitled

a guest
Apr 10th, 2020
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. from spellchecker import *
  2.  
  3. print('Welcome to Text File Spellchecker.')
  4. fileName = str(input('Enter the name of the file to read:'))
  5.  
  6.  
  7. def get_file(file):
  8.     try:
  9.         passed=0
  10.         failed=0
  11.         SP = spellchecker("english_words.txt")
  12.         linenumber = 0
  13.         with open (file) as f:
  14.             lines = f.readlines()
  15.             print()
  16.             for line in lines:
  17.                 linenumber+=1
  18.                 words = line.split()
  19.                 for word in words:
  20.                     if SP.check(word) == False:
  21.                         print('Possible Spelling Error on line {}: {}'.format(linenumber,word))
  22.                         failed+=1
  23.                     else:
  24.                         passed+=1
  25.                    
  26.         total=passed+failed
  27.         print("{} words passed spell checker.".format(total-failed))
  28.         print('{} words failed spell checker.'.format(failed))
  29.         percentPassed = ((failed/total)*100)-100
  30.         print('{:.2f}% of the words passed.'.format(abs(percentPassed)))
  31.     except:
  32.         print()
  33.         print("Could not open file.")
  34.         fileName = str(input('Enter the name of the file to read:'))
  35.         get_file(fileName)
  36.  
  37. get_file(fileName)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement