Skip to content

Commit f990d1b

Browse files
Add input validation to reverse_letters function
1 parent fc2f947 commit f990d1b

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

strings/reverse_letters.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ def reverse_letters(sentence: str, length: int = 0) -> str:
1212
>>> reverse_letters("racecar")
1313
'racecar'
1414
"""
15+
if not isinstance(sentence, str):
16+
raise TypeError("sentence must be a string")
17+
18+
if not isinstance(length, int) or length < 0:
19+
raise ValueError("length must be a non-negative integer")
20+
1521
return " ".join(
1622
word[::-1] if len(word) > length else word for word in sentence.split()
1723
)

0 commit comments

Comments
 (0)