diff --git a/circle.py b/circle.py new file mode 100644 index 0000000..8cf0fe8 --- /dev/null +++ b/circle.py @@ -0,0 +1,9 @@ +#create circle class +import numpy as np +class Circle: + def __init__(self, radius): + self.radius = radius + def area(self): + return np.pi * self.radius ** 2 + def perimeter(self): + return 2 * np.pi * self.radius \ No newline at end of file diff --git a/flask_app.py b/flask_app.py index 8897fa2..fb0a9e5 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 @@ -10,6 +12,24 @@ def home(): return render_template('home.html') +@app.route('/circle', methods=['GET', 'POST']) +def circle(): + if request.method == 'POST': + radius = request.form['radius'] + + try: + radius = convert_to_float(radius) + if radius <= 0: + return render_template('circle.html', printed_result = "Must be a positive Number.") + + circle = Circle(radius=radius) + area = circle.area() + perimeter = circle.perimeter() + return render_template('circle.html', printed_result = f'The area of you circle is {str(area)} and the perimeter is {str(perimeter)}') + except ValueError: + return render_template('circle.html', printed_result = "Invalid input!") + + return render_template('circle.html') @app.route('/calculate', methods=['GET', 'POST']) # associating the GET and POST method with this route def calculate(): diff --git a/templates/circle.html b/templates/circle.html new file mode 100644 index 0000000..432f9b0 --- /dev/null +++ b/templates/circle.html @@ -0,0 +1,12 @@ +{% extends 'layout.html' %} +{% block content %} +