Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/com/hankcs/algorithm/simple_utils.py
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions src/com/hankcs/algorithm/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

def reverse_string(text):
return text[::-1]


if __name__ == "__main__":
print(reverse_string("hello"))