From 8370bc09f071e6fc0d296e7805bdd089e98e1816 Mon Sep 17 00:00:00 2001 From: Javier de la Rosa Date: Mon, 9 Mar 2026 10:58:34 -0600 Subject: [PATCH 1/3] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3a87181..8671a90 100644 --- a/README.md +++ b/README.md @@ -110,3 +110,4 @@ An important principle of version control is that you **never** duplicate files. Great job! If you comfortably navigated these exercises, then you have the necessary basics for working with git and GitHub. These will get you most of the way through the course, and indeed, through your programming career. The most important topics that we haven't yet discussed are *merging* and *branching*, which are especially relevant when collaborating with others. We may come back to these in a future Discussion activity. Another topic that you might find useful to explore on your own is the `.gitignore` file. This file specifies files which should be *excluded* from tracking by git. This is handy if there are certain "junk" files that you would prefer not to see in GitHub Desktop. +Javier de la Rosa \ No newline at end of file From 765da14e47442ac1b29dc7bccf538eb467d5365d Mon Sep 17 00:00:00 2001 From: Javier de la Rosa Date: Mon, 9 Mar 2026 15:49:47 -0600 Subject: [PATCH 2/3] Updated Readme file and Added Calculator Script --- README.md | 3 +- calculator.py | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 calculator.py diff --git a/README.md b/README.md index 8671a90..cf2bcb2 100644 --- a/README.md +++ b/README.md @@ -110,4 +110,5 @@ An important principle of version control is that you **never** duplicate files. Great job! If you comfortably navigated these exercises, then you have the necessary basics for working with git and GitHub. These will get you most of the way through the course, and indeed, through your programming career. The most important topics that we haven't yet discussed are *merging* and *branching*, which are especially relevant when collaborating with others. We may come back to these in a future Discussion activity. Another topic that you might find useful to explore on your own is the `.gitignore` file. This file specifies files which should be *excluded* from tracking by git. This is handy if there are certain "junk" files that you would prefer not to see in GitHub Desktop. -Javier de la Rosa \ No newline at end of file + +I'm Javier de la Rosa and I edited this file! \ No newline at end of file diff --git a/calculator.py b/calculator.py new file mode 100644 index 0000000..ab09ba3 --- /dev/null +++ b/calculator.py @@ -0,0 +1,99 @@ +# calculator.py +# A minimal Flask web app that presents a form to enter two numbers and select an arithmetic operation. +# How to run: +# 1) Ensure Flask is installed: pip install flask +# 2) Start the app: python calculator.py +# 3) Open your browser at: http://127.0.0.1:5000/ + +from __future__ import annotations +from flask import Flask, request, render_template_string +from typing import Optional + +app = Flask(__name__) + +PAGE_TEMPLATE = """ + + + + + + Simple Calculator + + + +
+

Simple Calculator

+

Enter two numbers and choose an operation.

+ +
\n \n \n\n \n \n\n \n
\n \n \n \n \n
\n\n \n
\n\n {% if error %}\n
Error: {{ error }}
\n {% elif result is not none %}\n
Result: {{ result }}
\n {% endif %}\n
\n\n\n""" + + +def compute(a: float, b: float, op: str) -> float: + """Compute the operation on a and b. + + Args: + a: First number + b: Second number + op: One of 'plus', 'minus', 'times', 'divide' + Returns: + The computed float result. + Raises: + ValueError: If op is invalid or division by zero occurs. + """ + if op == "plus": + return a + b + elif op == "minus": + return a - b + elif op == "times": + return a * b + elif op == "divide": + if b == 0: + raise ValueError("Cannot divide by zero.") + return a / b + else: + raise ValueError("Invalid operation.") + + +@app.route("/", methods=["GET"]) +def index(): + # Initial page load with empty fields + return render_template_string(PAGE_TEMPLATE, a=None, b=None, op="plus", result=None, error=None) + + +@app.route("/calculate", methods=["POST"]) +def calculate(): + a_raw: Optional[str] = request.form.get("a") + b_raw: Optional[str] = request.form.get("b") + op: str = request.form.get("op", "plus") + + error: Optional[str] = None + result: Optional[float] = None + + try: + if a_raw is None or b_raw is None: + raise ValueError("Both numbers are required.") + a = float(a_raw) + b = float(b_raw) + result = compute(a, b, op) + except ValueError as e: + error = str(e) + + # Re-render page with the result or error and preserve inputs + return render_template_string(PAGE_TEMPLATE, a=a_raw, b=b_raw, op=op, result=result, error=error) + + +if __name__ == "__main__": + # Run the Flask development server + app.run(debug=True) From bdc0216e2be6c4201315147bab48a214fb55f01e Mon Sep 17 00:00:00 2001 From: Javier de la Rosa Date: Mon, 9 Mar 2026 16:18:03 -0600 Subject: [PATCH 3/3] Update README.md --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cf2bcb2..b0877e6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Practice with git and GitHub -\[Your Step 3 Edit Here\] +I'm Javier de la Rosa and I edited this file! This is a very simple repository for practicing with git and GitHub. git is a utility for *version control*. When a body of code is tracked with git, it is easy to see how the software has evolved over time, to roll back changes when needed, and to incorporate modifications by multiple collaborators. In this activity, we're going to focus on core git workflows for single-person projects. We may do a follow-up activity later in the quarter on workflows for collaborative projects. @@ -109,6 +109,4 @@ An important principle of version control is that you **never** duplicate files. Great job! If you comfortably navigated these exercises, then you have the necessary basics for working with git and GitHub. These will get you most of the way through the course, and indeed, through your programming career. The most important topics that we haven't yet discussed are *merging* and *branching*, which are especially relevant when collaborating with others. We may come back to these in a future Discussion activity. -Another topic that you might find useful to explore on your own is the `.gitignore` file. This file specifies files which should be *excluded* from tracking by git. This is handy if there are certain "junk" files that you would prefer not to see in GitHub Desktop. - -I'm Javier de la Rosa and I edited this file! \ No newline at end of file +Another topic that you might find useful to explore on your own is the `.gitignore` file. This file specifies files which should be *excluded* from tracking by git. This is handy if there are certain "junk" files that you would prefer not to see in GitHub Desktop. \ No newline at end of file