SHARE
TWEET

Untitled

a guest Jul 19th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import string
  2.  
  3.  
  4. def calculate_score(filename):
  5.     """Reads names and returns total scores."""
  6.     letter_scores = {letter: ord(letter) - 64 for letter in string.ascii_uppercase}
  7.     with open(filename) as names:
  8.         total = 0
  9.         names = sorted(names.read().replace('"', '').split(','))
  10.         for index, name in enumerate(names):
  11.             temp = 0
  12.             for letter in name:
  13.                 temp += letter_scores[letter]
  14.             total += temp * (index + 1)
  15.         return total
  16.  
  17.  
  18. if __name__ == '__main__':
  19.     print(calculate_score('p022_names.txt'))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top