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
12 changes: 12 additions & 0 deletions python/simple_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# simple_utils.py - A tiny utility library

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
Comment on lines +10 to +11
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add missing docstring and input validation.

The temperature conversion formula is mathematically correct. However, add docstring for consistency and input validation for robustness.

 def celsius_to_fahrenheit(celsius):
+    """Converts temperature from Celsius to Fahrenheit."""
+    if not isinstance(celsius, (int, float)):
+        raise TypeError("Input must be a number")
     return (celsius * 9/5) + 32
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def celsius_to_fahrenheit(celsius):
return (celsius * 9/5) + 32
def celsius_to_fahrenheit(celsius):
"""Converts temperature from Celsius to Fahrenheit."""
if not isinstance(celsius, (int, float)):
raise TypeError("Input must be a number")
return (celsius * 9/5) + 32
🤖 Prompt for AI Agents
In python/simple_utils.py around lines 10 to 11, add a docstring to the
celsius_to_fahrenheit function describing its purpose, input parameter, and
return value. Also, add input validation to check if the celsius argument is a
number (int or float) and raise a TypeError if not. This will improve code
clarity and robustness.