diff --git a/src/com/hankcs/algorithm/simple_utils.py b/src/com/hankcs/algorithm/simple_utils.py new file mode 100644 index 0000000..f7b95d6 --- /dev/null +++ b/src/com/hankcs/algorithm/simple_utils.py @@ -0,0 +1,19 @@ +def reverse_string(text): + """Reverses the characters in a string.""" + return text[::-1] + +def count_words(sentence): + return len(sentence.split()) + +def celsius_to_fahrenheit(celsius): + return (celsius * 9/5) + 32 + +def fibonacci(n): + if not isinstance(n, int): + raise TypeError("n must be a non-negative integer") + if n < 0: + raise ValueError("n must be non-negative") + a, b = 0, 1 + for _ in range(n): + a, b = b, a + b + return a diff --git a/src/com/hankcs/algorithm/test.py b/src/com/hankcs/algorithm/test.py new file mode 100644 index 0000000..6b835ef --- /dev/null +++ b/src/com/hankcs/algorithm/test.py @@ -0,0 +1,7 @@ + +def reverse_string(text): + return text[::-1] + + +if __name__ == "__main__": + print(reverse_string("hello")) \ No newline at end of file