diff --git a/circle.py b/circle.py new file mode 100644 index 0000000..12b9c2d --- /dev/null +++ b/circle.py @@ -0,0 +1,19 @@ +from math import pi +class Circle: + def __init__(self, radius): + self.radius = radius + + def perimeter(self): + return 2 * 3.14 * self.radius + + def area(self): + return 3.14 * self.radius * self.radius + +def circle_calc(radius, operation): + c = Circle(float(radius)) + if operation == 'perimeter': + return c.perimeter() + elif operation == 'area': + return c.area() + else: + return "Invalid operation" \ No newline at end of file diff --git a/flask_app.py b/flask_app.py index 8897fa2..8cf6d75 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_calc + app = Flask(__name__) # create the instance of the flask class @@ -38,3 +40,19 @@ 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 circle_calculation(): + if request.method == 'POST': + radius = request.form['radius'] + operation = request.form['operation'] + result = circle_calc(radius, operation) + return render_template('circle.html', printed_result=result) + else: + return render_template('circle.html') + + + +if __name__ == '__main__': + app.run(debug=True) # run the application diff --git a/templates/circle.html b/templates/circle.html new file mode 100644 index 0000000..0386ddf --- /dev/null +++ b/templates/circle.html @@ -0,0 +1,24 @@ +{% extends 'layout.html' %} +{% block content %} +
+