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 buggy_temperature.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def celsius_to_fahrenheit(celsius):
# Bug fixed: correct formula C * 9/5 + 32
fahrenheit = celsius * 9/5 + 32
return fahrenheit

def fahrenheit_to_celsius(fahrenheit):
# Bug fixed: correct order of operations (F - 32) * 5/9
celsius = (fahrenheit - 32) * 5/9
return celsius

print(f"100°C = {celsius_to_fahrenheit(100)}°F")
print(f"212°F = {fahrenheit_to_celsius(212)}°C")
Comment on lines +11 to +12
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Avoid import-time side effects; gate demo prints with main.

Top-level prints execute on import, which can break consumers/tests.

-print(f"100°C = {celsius_to_fahrenheit(100)}°F")
-print(f"212°F = {fahrenheit_to_celsius(212)}°C")
+if __name__ == "__main__":
+    print(f"100°C = {celsius_to_fahrenheit(100)}°F")
+    print(f"212°F = {fahrenheit_to_celsius(212)}°C")
📝 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
print(f"100°C = {celsius_to_fahrenheit(100)}°F")
print(f"212°F = {fahrenheit_to_celsius(212)}°C")
if __name__ == "__main__":
print(f"100°C = {celsius_to_fahrenheit(100)}°F")
print(f"212°F = {fahrenheit_to_celsius(212)}°C")
🤖 Prompt for AI Agents
In buggy_temperature.py around lines 11 to 12 the module contains top-level demo
print statements that run on import; move those prints into a guarded block so
they only run when the module is executed directly: wrap the two print calls in
an if __name__ == "__main__": block (indent them accordingly) so importing the
module by tests or other code won’t produce side-effect output.