Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
20 changes: 20 additions & 0 deletions flask_calc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from flask import Flask, render_template, request

calc_app = Flask(__name__)

@calc_app.route('/')
def form():
return render_template('calculator.html')


@calc_app.route('/calculator', methods=["POST"])
def calculate():
first = str(request.form['first'])
operator = str(request.form['operator'])
second = str(request.form['second'])
result = eval(first+operator+second)
return render_template("calc_result.html", result=result)


if __name__ == "__main__":
calc_app.run(debug=True)
Binary file added templates/.DS_Store
Binary file not shown.
37 changes: 37 additions & 0 deletions templates/calc_result.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<html>
<head>
<title>CALC MORE!</title>
</head>

<body>
<h1>Your Answer:</h1>
<p1> {{ result }} </p1>

<h2>
<img src=http://www.math.unl.edu/~s-khall13/mathrules.jpg alt="Math Rules"
/>
<h1>Let's do some more MATH!!!</h1>
<strong>Input 2 values and select an operator.</strong>
<form action="/calculator" method="POST" >
<div class=first>
First Value:
<input id="first-operand" type="text" name="first" value="{{ result }}"></input>
</div>
<div class="Operator">
<select id="the-operator" name="operator">
<option>+</option>
<option>-</option>
<option>*</option>
<option>/</option>
<option>**</option>
<option>%</option>
</select>
</div>
<div class=second>
Second Value:
<input id="second-operand" type="text" name="second"></input>
</div>
<input type=submit value="Calculate!"</input>
</form>
</body>
</html>
31 changes: 31 additions & 0 deletions templates/calculator.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<html>
<head>
<title>Calc that!</title>
</head>

<body>
<h1>Python Web Calculator</h1>
<strong>Input 2 values and select an operator.</strong>
<form action="/calculator" method="POST" >
<div class=first>
First Value:
<input id="first-operand" type="text" name="first"></input>
</div>
<div class="Operator">
<select id="the-operator" name="operator">
<option>+</option>
<option>-</option>
<option>*</option>
<option>/</option>
<option>**</option>
<option>%</option>
</select>
</div>
<div class=second>
Second Value:
<input id="second-operand" type="text" name="second"></input>
</div>
<input type=submit value="Calculate!"</input>
</form>
</body>
</html>