Advertisement
Guest User

AlphaCount.py

a guest
Sep 17th, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. score = {"a": 1, "b": 2, "c": 3, "d": 4, "e": 5, "f": 6,
  2.          "g": 7, "h": 8, "i": 9, "j": 10, "k": 11, "l": 12,
  3.          "m": 13, "n": 14, "o": 15, "p": 16, "q": 17, "r": 18,
  4.          "s": 19, "t": 20, "u": 21, "v": 22, "w": 23, "x": 24,
  5.          "y": 25, "z": 26}
  6.          
  7. file = open("output.txt", "w")
  8.          
  9. def alpha_score(word):
  10.     word = word.lower()
  11.     result = 0
  12.     for i in word:
  13.         result += score[i]
  14.     return result
  15.  
  16. words = []
  17. fin = open('words.txt')
  18. for line in fin:
  19.     words.append(line.strip())
  20.  
  21. count = 0
  22. results = 0
  23. for word in words:
  24.     count += 1
  25.     if alpha_score(word) == 100:
  26.         file.write(word+'\n')
  27.         results += 1
  28.  
  29. file.close()
  30. print "%s words found out of %s" % (results, count)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement