From 993c4c06fcd97f8bff6f591e4f6c9f8ef4c370d1 Mon Sep 17 00:00:00 2001 From: ViswaNikhitha <2400100046@kluniversity.in> Date: Thu, 1 Jan 2026 14:34:13 +0530 Subject: [PATCH 1/2] Create circle.py --- circle.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 circle.py diff --git a/circle.py b/circle.py new file mode 100644 index 0000000..bfe0f32 --- /dev/null +++ b/circle.py @@ -0,0 +1,15 @@ +import math + +def circle_properties(radius): + area = math.pi * radius * radius + circumference = 2 * math.pi * radius + return area, circumference + + +# Example usage +r = 5 +area, circumference = circle_properties(r) + +print("Radius:", r) +print("Area:", round(area, 2)) +print("Circumference:", round(circumference, 2)) From 87995d7832a91148b19904954d9f3a2b6cf844e7 Mon Sep 17 00:00:00 2001 From: ViswaNikhitha <2400100046@kluniversity.in> Date: Thu, 1 Jan 2026 14:57:43 +0530 Subject: [PATCH 2/2] Update circle.py --- circle.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/circle.py b/circle.py index bfe0f32..18bd27f 100644 --- a/circle.py +++ b/circle.py @@ -1,15 +1,56 @@ -import math +""" +Circle Properties Calculation + +Description: +This algorithm calculates the area and circumference of a circle given its radius. +It uses the formulas: + Area = π * r^2 + Circumference = 2 * π * r + +Approach: +- Take the radius as input +- Compute area and circumference +- Return both values + +Use Cases: +- Geometry calculations +- Basic math learning +- DSA practice examples + +Time Complexity: O(1) +- All calculations are done in constant time, independent of input size. + +Space Complexity: O(1) +- Uses only a few variables, no extra data structures needed. +""" + +import math # Import math module to access pi def circle_properties(radius): + """ + Calculates area and circumference of a circle given its radius + :param radius: Radius of the circle + :return: Tuple (area, circumference) or error message for negative radius + """ + # Validate input + if radius < 0: + return "Error: Radius cannot be negative" + + # Calculate area using formula π * r^2 area = math.pi * radius * radius + + # Calculate circumference using formula 2 * π * r circumference = 2 * math.pi * radius + + # Return both results return area, circumference +# Example usage / Test cases +if __name__ == "__main__": + test_radii = [5, 0, -3] # Different test cases including edge cases -# Example usage -r = 5 -area, circumference = circle_properties(r) - -print("Radius:", r) -print("Area:", round(area, 2)) -print("Circumference:", round(circumference, 2)) + for r in test_radii: + result = circle_properties(r) + print(f"Radius: {r}") + print(f"Result: {result}") + print("-" * 30)