-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
37 lines (23 loc) · 777 Bytes
/
Copy pathapp.py
File metadata and controls
37 lines (23 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from flask import Flask, render_template, request
app = Flask(__name__)
@app.route("/", methods=["GET", "POST"])
def home():
result = ""
if request.method == "POST":
num1 = float(request.form["num1"])
num2 = float(request.form["num2"])
operation = request.form["operation"]
if operation == "+":
result = num1 + num2
elif operation == "-":
result = num1 - num2
elif operation == "*":
result = num1 * num2
elif operation == "/":
if num2 == 0:
result = "Cannot divide by zero"
else:
result = num1 / num2
return render_template("index.html", result=result)
if __name__ == "__main__":
app.run(debug=True)