diff --git a/.ipynb_checkpoints/PS_2-checkpoint.ipynb b/.ipynb_checkpoints/PS_2-checkpoint.ipynb new file mode 100644 index 0000000..3ab262c --- /dev/null +++ b/.ipynb_checkpoints/PS_2-checkpoint.ipynb @@ -0,0 +1,72 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "id": "2f7f52aa-92b7-4fd5-8fe9-06595d36f633", + "metadata": {}, + "outputs": [ + { + "ename": "IndentationError", + "evalue": "expected an indented block after 'for' statement on line 2 (4110982641.py, line 3)", + "output_type": "error", + "traceback": [ + "\u001b[0;36m Cell \u001b[0;32mIn[2], line 3\u001b[0;36m\u001b[0m\n\u001b[0;31m if input [idx ][0] == \"1\":\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mIndentationError\u001b[0m\u001b[0;31m:\u001b[0m expected an indented block after 'for' statement on line 2\n" + ] + } + ], + "source": [ + "def check_array ( input ):\n", + " for idx in range (len( input )):\n", + " if input [idx ][0] == \"1\":\n", + " input [idx] = None\n", + " return input\n", + "\n", + "original_array = [\"1_3\", \"5_2\"]\n", + "\n", + " new_array = check_array ( original_array )\n", + "\n", + " print ( original_array )\n", + " print ( new_array )" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e146596b-d2eb-4979-97db-ce5cbb8e4353", + "metadata": {}, + "outputs": [], + "source": [ + "max_sum = None\n", + " for i in range (len ( array )):\n", + " sum_subarray = 0\n", + " for j in range (i, len( array )):\n", + " sum_subarray += array [j]\n", + " if max_sum is None or max_sum < sum_subarray :\n", + " max_sum = sum_subarray\n", + " print ( max_sum )" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.5" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/circle.py b/circle.py new file mode 100644 index 0000000..db69900 --- /dev/null +++ b/circle.py @@ -0,0 +1,9 @@ +## Calculation for area and permiter +import math +class Circle: + def __init__(self, radius: float): + self.radius = radius + def perimeter_calculation(self) -> float: ## Perimeter Method + return 2 * math.pi * self.radius + def area_calculation(self) -> float: ## Area Method + return math.pi * self.radius ** 2 \ No newline at end of file diff --git a/flask_app.py b/flask_app.py index 8897fa2..1f33f0e 100644 --- a/flask_app.py +++ b/flask_app.py @@ -1,6 +1,7 @@ from flask import Flask, render_template, request - from helper import perform_calculation, convert_to_float +## We need this package in order to perform the circle calculations +from circle import Circle app = Flask(__name__) # create the instance of the flask class @@ -38,3 +39,27 @@ def calculate(): return render_template('calculator.html', printed_result="You cannot divide by zero") return render_template('calculator.html') + + +### Aranxa Márquez: PS_2 + +@app.route('/circle', methods=['GET', 'POST']) +def circle(): + printed_result = None # Initialize printed_result variable + + if request.method == 'POST': + radius = float(request.form['radius']) # Correctly extract radius from form data + operation = request.form['operation'] + + circle = Circle(radius) # Create a Circle instance with the given radius + + if operation == 'perimeter': + result = circle.perimeter_calculation() + printed_result = f"The perimeter of the circle is: {result}" + elif operation == 'area': + result = circle.area_calculation() + printed_result = f"The area of the circle is: {result}" + else: + printed_result = 'Operation must be one of "area", "perimeter"' + + return render_template('circle.html', printed_result=printed_result) \ No newline at end of file diff --git a/templates/circle.html b/templates/circle.html new file mode 100644 index 0000000..0dd9536 --- /dev/null +++ b/templates/circle.html @@ -0,0 +1,19 @@ +{% extends 'layout.html' %} +{% block content %} +
{{ printed_result }}
+ {% endif %} +{% endblock %} \ No newline at end of file diff --git a/templates/layout.html b/templates/layout.html index 8de2e62..7668846 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -5,20 +5,23 @@ - +