diff --git a/flask_app.py b/flask_app.py index 8897fa2..b37700b 100644 --- a/flask_app.py +++ b/flask_app.py @@ -1,16 +1,17 @@ +# Import Flask class from flask import Flask, render_template, request - from helper import perform_calculation, convert_to_float +from helper_circle import circle_perform +# Create Flask object app = Flask(__name__) # create the instance of the flask class - @app.route('/') @app.route('/home') def home(): return render_template('home.html') - +#Creating home route and returning home HTML @app.route('/calculate', methods=['GET', 'POST']) # associating the GET and POST method with this route def calculate(): if request.method == 'POST': @@ -38,3 +39,28 @@ def calculate(): return render_template('calculator.html', printed_result="You cannot divide by zero") return render_template('calculator.html') + +#Creating circle route and returning circle HTML +@app.route('/circle', methods=['GET', 'POST']) # associating the GET and POST method with this route +def circle(): + printed_result = None + + if request.method == 'POST': + radius = float(request.form['radius']) + operation = request.form['operation'] + + # Create an instance + helper_circle = circle_perform(radius) + + if radius < 0: + printed_result = 'Radius must not be defined as negative.' + elif operation not in ['Perimeter', 'Area']: + printed_result = 'Operation must be one of "Perimeter", or "Area".' + elif operation == 'Perimeter': + result = helper_circle.perimeter() + printed_result = f"Perimeter: {result}" + else: + result = helper_circle.area() + printed_result = f"Area: {result}" + + return render_template('circle.html', printed_result=printed_result) \ No newline at end of file diff --git a/helper_circle.py b/helper_circle.py new file mode 100644 index 0000000..774d496 --- /dev/null +++ b/helper_circle.py @@ -0,0 +1,9 @@ +# create helper_circle functions for circle calculations +import math +class circle_perform: + def __init__(self, radius: float): + self.radius=radius + def perimeter(self) -> float: + return 2*math.pi*self.radius + def area(self) -> float: + return math.pi*(self.radius**2) \ No newline at end of file diff --git a/templates/circle.html b/templates/circle.html new file mode 100644 index 0000000..ae98756 --- /dev/null +++ b/templates/circle.html @@ -0,0 +1,20 @@ +{% extends 'layout.html' %} +{% block content %} +