Skip to content
Closed
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,13 +1,39 @@
# simple_utils.py - A tiny utility library

def reverse_string(text):
"""Reverses the characters in a string."""
"""
Return a new string with the characters of the input string in reverse order.

Parameters:
text (str): The string to be reversed.

Returns:
str: The reversed string.
"""
return text[::-1]

def count_words(sentence):
"""
Return the number of words in a sentence by splitting on whitespace.

Parameters:
sentence (str): The input string to count words from.

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

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

Parameters:
celsius (float): Temperature value in degrees Celsius.

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