aboutsummaryrefslogtreecommitdiff
path: root/challenge-272/steven-wilson/python
diff options
context:
space:
mode:
authorSteven <steven1170@zoho.eu>2024-06-03 17:34:31 +0100
committerSteven <steven1170@zoho.eu>2024-06-03 17:34:31 +0100
commite74007a0298a28ce431df61a219086397a560901 (patch)
treef91cdd554f0a52c909d5bd7f774b8f42415af811 /challenge-272/steven-wilson/python
parent6006e625cdb6ccb9bf4bae4ff0b6bfff27ba2c59 (diff)
downloadperlweeklychallenge-club-e74007a0298a28ce431df61a219086397a560901.tar.gz
perlweeklychallenge-club-e74007a0298a28ce431df61a219086397a560901.tar.bz2
perlweeklychallenge-club-e74007a0298a28ce431df61a219086397a560901.zip
add some argument validation
Diffstat (limited to 'challenge-272/steven-wilson/python')
-rw-r--r--challenge-272/steven-wilson/python/ch-2.py3
1 files changed, 3 insertions, 0 deletions
diff --git a/challenge-272/steven-wilson/python/ch-2.py b/challenge-272/steven-wilson/python/ch-2.py
index d33962b413..f92d1c2528 100644
--- a/challenge-272/steven-wilson/python/ch-2.py
+++ b/challenge-272/steven-wilson/python/ch-2.py
@@ -13,6 +13,9 @@ def string_score(string):
>>> string_score('raku')
37
'''
+ if len(string) < 2:
+ raise ValueError("String argument should have at least 2 characters.")
+
return sum(abs(ord(a) - ord(b)) for a, b in zip(string, string[1:]))