Skip to content

Instantly share code, notes, and snippets.

@asserchiu
Created May 21, 2015 10:08
Show Gist options
  • Save asserchiu/68b0e95e7b2b79f547bd to your computer and use it in GitHub Desktop.
Save asserchiu/68b0e95e7b2b79f547bd to your computer and use it in GitHub Desktop.
Score a word with a: 1, b: 2, ..., z: 26.
#!/usr/bin/python
# -*- coding: utf-8 -*-
def score_a_word(word=''):
# TODO: add exception!
sum = 0
for char in word.lower():
sum += (ord(char) - 96)
print(word + ' for ' + str(sum))
return sum
if __name__ == '__main__':
score_a_word('knowledge')
score_a_word('hardwork')
score_a_word('attitude')
score_a_word('Pneumonoultramicroscopicsilicovolcanoconiosis')
@asserchiu
Copy link
Author

knowledge for 96
hardwork for 98
attitude for 100
Pneumonoultramicroscopicsilicovolcanoconiosis for 560

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment