Skip to content
Open
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
28 changes: 27 additions & 1 deletion simple_utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
# simple_utils.py - A tiny utility library

def reverse_string(text):
"""Reverses the characters in a string."""
"""
Reverses the characters in a string.

Args:
text: The string to reverse.

Returns:
A new string with the characters of text in reverse order.
"""
return text[::-1]

def count_words(sentence):
"""
Counts the number of words in a sentence.

Args:
sentence: The input string to analyze.

Returns:
The number of words separated by whitespace in the sentence.
"""
return len(sentence.split())

def celsius_to_fahrenheit(celsius):
"""
Converts a temperature from Celsius to Fahrenheit.

Args:
celsius: Temperature value in degrees Celsius.

Returns:
The equivalent temperature in degrees Fahrenheit.
"""
return (celsius * 9/5) + 32