diff options
Diffstat (limited to 'challenge-272/sgreen/python/ch-2.py')
| -rwxr-xr-x | challenge-272/sgreen/python/ch-2.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/challenge-272/sgreen/python/ch-2.py b/challenge-272/sgreen/python/ch-2.py new file mode 100755 index 0000000000..2a05a1f811 --- /dev/null +++ b/challenge-272/sgreen/python/ch-2.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 + +import sys + + +def string_store(word: str) -> int: + """ + Calculates the score of a given word based on the absolute difference + between ASCII values of consecutive characters. + + Args: + word (str): The input word. + + Returns: + int: The score of the word. + """ + + score = 0 + + # Convert the string to a list of ASCII values + ascii_values = [ord(char) for char in word] + + # Calculate the score + for pos in range(len(ascii_values)-1): + score += abs(ascii_values[pos] - ascii_values[pos+1]) + + return score + + +def main(): + result = string_store(sys.argv[1]) + print(result) + + +if __name__ == '__main__': + main() |
