Created
May 21, 2015 10:08
-
-
Save asserchiu/68b0e95e7b2b79f547bd to your computer and use it in GitHub Desktop.
Score a word with a: 1, b: 2, ..., z: 26.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
knowledge for 96
hardwork for 98
attitude for 100
Pneumonoultramicroscopicsilicovolcanoconiosis for 560