diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..928c479 Binary files /dev/null and b/.DS_Store differ diff --git a/DSA_homework2.pdf b/DSA_homework2.pdf new file mode 100644 index 0000000..c3d12c8 Binary files /dev/null and b/DSA_homework2.pdf differ diff --git a/DS_A_Assignment_2.pdf b/DS_A_Assignment_2.pdf new file mode 100644 index 0000000..6989f07 Binary files /dev/null and b/DS_A_Assignment_2.pdf differ diff --git a/circle.py b/circle.py new file mode 100644 index 0000000..1b0f699 --- /dev/null +++ b/circle.py @@ -0,0 +1,34 @@ +# create helper functions for simple circular geometry calculations + +from math import pi + +class Circle: + def __init__ (self, radius): + self.radius = radius + + def circle_calculation(self, operation:str) -> float: + """"" + Calculates perimeter/area of circle with given radius. + + Parameters: + radius (float): radius of given circle + + Returns: + float: The perimeter/area of the circle. + """"" + if not isinstance(self.radius, (int, float)): + return "Cannot perform operation with this input" + + if self.radius < 0: + return "Invalid input for radius" + + if operation == 'perimeter': + result = float(2 * pi * self.radius) + + elif operation == 'area': + result = float(pi * self.radius ** 2) + + else: + raise ValueError("Invalid operation. Please specify 'perimeter' or 'area'.") + + return result diff --git a/flask_app.py b/flask_app.py index 8897fa2..c2d2b63 100644 --- a/flask_app.py +++ b/flask_app.py @@ -1,6 +1,6 @@ from flask import Flask, render_template, request - from helper import perform_calculation, convert_to_float +from circle import Circle app = Flask(__name__) # create the instance of the flask class @@ -38,3 +38,26 @@ def calculate(): return render_template('calculator.html', printed_result="You cannot divide by zero") return render_template('calculator.html') + + +@app.route('/calculate_circle', methods=['GET', 'POST']) +def calculate_circle(): + if request.method == 'POST': + radius = request.form['radius'] + operation = str(request.form['operation']) + + try: + radius = convert_to_float(value=radius) + except ValueError: + return render_template('circle_calculator.html', printed_result="Cannot perform operation with this input") + + circle = Circle(radius) + result = circle.circle_calculation(operation=operation) + return render_template('circle_calculator.html', printed_result=str(result)) + + return render_template('circle_calculator.html') + + + +if __name__ == "__main__": + app.run(debug=True) \ No newline at end of file diff --git a/questions 2_3.docx b/questions 2_3.docx new file mode 100644 index 0000000..d4ec331 Binary files /dev/null and b/questions 2_3.docx differ diff --git a/static/.DS_Store b/static/.DS_Store new file mode 100644 index 0000000..846bf79 Binary files /dev/null and b/static/.DS_Store differ diff --git a/static/main.css b/static/main.css index dfe5192..3b241c9 100644 --- a/static/main.css +++ b/static/main.css @@ -1,10 +1,16 @@ +@import url('https://fonts.googleapis.com/css2?family=Comic+Neue&family=Papyrus&display=swap'); + + /* Global Styles */ body { - font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; - background-color: #f8f9fa; - color: #333; + font-family: 'Comic Neue', cursive, Tahoma, Geneva, Verdana, sans-serif; + font-size: 1em; + background-color: #2d7ccb; + color: #ffffff; margin: 0; padding: 0; + background-image: url('tie_dye.jpg'); + background-size: cover } .container { @@ -13,6 +19,14 @@ body { padding: 20px; } +h1 { + font-family: 'Comic Sans MS', 'Comic Sans', cursive; + font-size: 4em; + color: #FFFFFF; + font-weight: bold; + padding: 20px; +} + /* Header Styles */ header { background-color: #343a40; /* Dark neutral color for header */ @@ -56,8 +70,12 @@ h1 a { h1 a:hover { color: #ffafcc; + text-decoration: underline; /* re-adds underline on hover */ } + + + .menu li a:hover { color: #bde0fe; /* Light pastel color on hover */ } @@ -67,7 +85,7 @@ h1 { text-align: center; margin-top: 0; font-size: 36px; - color: #343a40; /* Dark neutral color for heading */ + color: #ffffff; /* Dark neutral color for heading */ } form { @@ -86,14 +104,19 @@ button { } button { - background-color: #343a40; /* Dark neutral color for button */ - color: #fff; + background-color: #FF69B4; + color: #FFFFFF; + font-family: 'Comic Neue', cursive; border: none; + padding: 10px 20px; + text-align: center; + display: inline-block; + margin: 4px 2px; cursor: pointer; - font-size: 16px; - transition: background-color 0.3s ease; /* Smooth transition for background color change */ + border-radius: 12px; + transition: background-color 0.3s ease; } button:hover { - background-color: #23272b; /* Slightly darker color on hover */ + background-color: #FFB6C1; } diff --git a/static/tie_dye.jpg b/static/tie_dye.jpg new file mode 100644 index 0000000..8fad555 Binary files /dev/null and b/static/tie_dye.jpg differ diff --git a/templates/calculator.html b/templates/calculator.html index 3dd1105..ed6df1c 100644 --- a/templates/calculator.html +++ b/templates/calculator.html @@ -1,6 +1,6 @@ {% extends 'layout.html' %} {% block content %} -

Calculator

+

General Calculator

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

Circle Calculator

+ + + + + + + +
+ +
+ + {{ printed_result }} + +{% endblock %} 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/test_circle.py b/test_circle.py new file mode 100644 index 0000000..6177a2d --- /dev/null +++ b/test_circle.py @@ -0,0 +1,84 @@ + +from circle import Circle +from math import isclose + +# area tests +def test_circle_calculation_area_int(): + circle = Circle(5) + actual_area_5 = circle.circle_calculation('area') + expected_area_5 = 78.53981633974483 + assert isclose(actual_area_5, expected_area_5, rel_tol=1e-9), f"Expected {expected_area_5}, but got {actual_area_5}" + +def test_circle_calculation_area_float(): + circle = Circle(4.9) + actual_area_4_9 = circle.circle_calculation('area') + expected_area_4_9 = 75.429639612691 + assert isclose(actual_area_4_9, expected_area_4_9, rel_tol=1e-9), f"Expected {expected_area_4_9}, but got {actual_area_4_9}" + +def test_circle_calculation_area_0(): + circle = Circle(0) + assert circle.circle_calculation("area") == 0 + +def test_circle_calculation_area_neg(): + circle = Circle(-1) + assert circle.circle_calculation("area") == "Invalid input for radius" + +def test_circle_calculation_area_tiny(): + circle = Circle(0.0001) + actual_area_tiny = circle.circle_calculation('area') + expected_area_tiny = 3.141592653589793e-08 + assert isclose(actual_area_tiny, expected_area_tiny, rel_tol=1e-9), f"Expected {expected_area_tiny}, but got {actual_area_tiny}" + +def test_circle_calculation_area_string(): + circle = Circle("HelloWorld") + assert circle.circle_calculation("area") == "Cannot perform operation with this input" + +# perimeter tests + +def test_circle_calculation_perimeter_int(): + circle = Circle(5) + actual_perimeter_5 = circle.circle_calculation('perimeter') + expected_perimeter_5 = 31.41592653589793 + assert isclose(actual_perimeter_5, expected_perimeter_5, rel_tol=1e-9), f"Expected {expected_area_5}, but got {actual_perimeter_5}" + +def test_circle_calculation_perimeter_float(): + circle = Circle(4.9) + actual_perimeter_4_9 = circle.circle_calculation('perimeter') + expected_perimeter_4_9 = 30.78760800518 + assert isclose(actual_perimeter_4_9, expected_perimeter_4_9, rel_tol=1e-9), f"Expected {expected_perimeter_4_9}, but got {actual_perimeter_4_9}" + +def test_circle_calculation_perimeter_0(): + circle = Circle(0) + assert circle.circle_calculation("perimeter") == 0 + +def test_circle_calculation_perimeter_neg(): + circle = Circle(-1) + assert circle.circle_calculation("perimeter") == "Invalid input for radius" + +def test_circle_calculation_perimeter_tiny(): + circle = Circle(0.0001) + actual_perimeter_tiny = circle.circle_calculation("perimeter") + expected_perimeter_tiny = 0.00062831853071796 + assert isclose(actual_perimeter_tiny, expected_perimeter_tiny, rel_tol=1e-9), f"Expected {expected_perimeter_tiny}, but got {actual_perimeter_tiny}" + +def test_circle_calculation_perimeter_string(): + circle = Circle("HelloWorld") + assert circle.circle_calculation("area") == "Cannot perform operation with this input" + +def run_tests(): + test_circle_calculation_area_int() + test_circle_calculation_area_float() + test_circle_calculation_area_0() + test_circle_calculation_area_neg() + test_circle_calculation_area_tiny() + test_circle_calculation_area_string() + test_circle_calculation_perimeter_int() + test_circle_calculation_perimeter_float() + test_circle_calculation_perimeter_0() + test_circle_calculation_perimeter_neg() + test_circle_calculation_perimeter_tiny() + test_circle_calculation_perimeter_string() + print("All tests passed!") # if any assertions fail, AssertionError will be raised + +if __name__ == "__main__": + run_tests() \ No newline at end of file