diff --git a/README.md b/README.md index 6c55806..feb88ba 100644 --- a/README.md +++ b/README.md @@ -1,53 +1 @@ -# Web calculator - -## Description - -Create a simple web-based calculator using Flask. - -## Objectives - -### Learning Objectives - -After completing this assignment, you should understand: - -* The very basics of making a web application - -### Performance Objectives - -After completing this assignment, you should be able to: - -* Create a Flask app - -## Details - -### Deliverables - -* A Git repo called web-calculator containing at least: - * `README.md` file explaining how to run your project - * a `requirements.txt` file - * a suite of tests for your project - -### Requirements - -* Passing unit tests -* No PEP8 or Pyflakes warnings or errors - -## Normal Mode - -Create a simple web application that works as a calculator. The first page, which you get via a GET request, should have a form with two text boxes, a dropdown box for the operation (+, -, *, /) and a button to calculate. - -The form uses POST to go to a second screen which shows the results of your calculation. - -## Hard Mode - -In addition to the requirements from **Normal Mode**: - -1. The form should also appear on the second page -- the calculation results page. The first operand should be filled in with the results of the previous calculation. - -2. Add [Foundation](http://foundation.zurb.com/) or [Bootstrap](http://getbootstrap.com/) to your application to make it look nicer. - -## Additional Resources - -* [The main Flask site](http://flask.pocoo.org/) -* [Explore Flask](https://exploreflask.com/) -* [Full Stack Python](http://www.fullstackpython.com/) +Enter a numerical value into each of the empty boxes and choose an operator from the drop-down menu. Click the "Calculate" button to see the result. diff --git a/templates/calculator.html b/templates/calculator.html new file mode 100644 index 0000000..b80a9fb --- /dev/null +++ b/templates/calculator.html @@ -0,0 +1,26 @@ + + + + + Web Calculator + + +
+

Calculator

+
+ + +
+ +
+ + + +
+ + diff --git a/templates/result.html b/templates/result.html new file mode 100644 index 0000000..2cf1264 --- /dev/null +++ b/templates/result.html @@ -0,0 +1,28 @@ + + + + + Web Calculator + + +
+

Calculator

+

Your result is: + {{ result }}

+
+ + +
+ +
+ + + +
+ + diff --git a/web_calculator.py b/web_calculator.py new file mode 100644 index 0000000..7c9a510 --- /dev/null +++ b/web_calculator.py @@ -0,0 +1,21 @@ +from flask import Flask, request, render_template + +app = Flask(__name__) + +@app.route("/") +def home(): + return render_template('calculator.html') + +@app.route('/calculator.html', methods=['POST', 'GET']) +def calculate(): + value1 = request.form['value1'] + value2 = request.form['value2'] + operator = request.form['operator'] + result = eval(value1 + operator + value2) + + return render_template('result.html'), result + + + +if __name__ == "__main__": + app.run(debug=True)