-
Notifications
You must be signed in to change notification settings - Fork 0
/
name-scores.py
46 lines (38 loc) · 1.27 KB
/
name-scores.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import time
import sys
import os.path
start = time.clock()
fname = "names.txt"
#Random name order
#with open(fname) as f:
#content = f.readlines()
#random.shuffle(content)
#for s in content:
# print s
if os.path.isfile(fname) == 0:
print 'The txt file does not exist. It may have been removed.'
sys.exit()
with open(fname) as f:
content = f.readlines()
#for s in content:
# print s
count = 0
for x in sorted(content):
count += 1
x = x.lower().rstrip('\n')
#print x
namelist = list(x)
charnum = []
for character in list(x):
number = ord(character)-96
#print number
charnum.insert(0, number)
#print charnum
charnum = list(reversed(charnum))
charcnumsum = sum(charnum)
result = count * charcnumsum
print str(count) + '. ' + x.title() + ' (' + str(count) + ' x ' + str(charcnumsum) + ') = ' + str(result)
result += result
print '\n#---------------------------------------------------------\nTotal of all the name scores in file = ' + str(result) + '\n---------------------------------------------------------#\n'
end = time.clock()
print 'Total execution time: ' + str(end - start) + ' sec'