diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..66544f0 Binary files /dev/null and b/.DS_Store differ diff --git a/circle.py b/circle.py new file mode 100644 index 0000000..b517c00 --- /dev/null +++ b/circle.py @@ -0,0 +1,13 @@ +import math + +class Circle: + def __init__(self,radius): + self.radius = radius + + def perimeter(self): + return 2 * math.pi * self.radius + + def area(self): + return math.pi * (self.radius ** 2) + + diff --git a/flask_app.py b/flask_app.py index 8897fa2..61c3cad 100644 --- a/flask_app.py +++ b/flask_app.py @@ -2,6 +2,8 @@ from helper import perform_calculation, convert_to_float +from circle import Circle + app = Flask(__name__) # create the instance of the flask class @@ -38,3 +40,14 @@ def calculate(): return render_template('calculator.html', printed_result="You cannot divide by zero") return render_template('calculator.html') + + +@app.route('/circle', methods=['GET', 'POST']) +def calculate_circle(): + if request.method == 'POST': + radius = float(request.form['radius']) + circle = Circle(radius) + perimeter = circle.perimeter() + area = circle.area() + return render_template('radius.html', perimeter=perimeter, area=area) + return render_template('radius.html') diff --git a/templates/layout.html b/templates/layout.html index 8de2e62..7986008 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -12,6 +12,7 @@

Home

diff --git a/templates/radius.html b/templates/radius.html new file mode 100644 index 0000000..3ea2a49 --- /dev/null +++ b/templates/radius.html @@ -0,0 +1,19 @@ +{% extends 'layout.html' %} +{% block content %} +
+

Circle Calculator

+
+
+ + +
+ +
+ {% if perimeter and area %} +
+

Perimeter: {{ perimeter }}

+

Area: {{ area }}

+
+ {% endif %} +
+{% endblock %} diff --git a/test_circle.py b/test_circle.py new file mode 100644 index 0000000..b2bf612 --- /dev/null +++ b/test_circle.py @@ -0,0 +1,22 @@ + +from circle import Circle +import math + +def test_circle(): + # Test case for perimeter + radius = 5 + circle = Circle(radius) + + expected_perimeter = 2 * math.pi * radius + assert circle.perimeter() == expected_perimeter, f"Expected perimeter: {expected_perimeter}, but got: {circle.perimeter()}" + + # Test case for area + expected_area = math.pi * (radius ** 2) + assert circle.area() == expected_area, f"Expected area: {expected_area}, but got: {circle.area()}" + + + print("All tests passed!") + + +if __name__ == "__main__": + test_circle() \ No newline at end of file