forked from khanfarhan10/SimpleCalcEvalPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
53 lines (41 loc) · 1.37 KB
/
app.py
File metadata and controls
53 lines (41 loc) · 1.37 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""Helllo World!
Python program using Flask for a simple Calculator
GUI using the flask module
"""
# import Flask Library
from flask import Flask, render_template, request
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
# return '<h1>Hi, Welcome to this session</h1>'
@app.route('/send', methods=['POST'])
def send():
if request.method == 'POST':
x = request.form['x']
# print(x)
# if x is blank or
if x == "":
pass
else:
try:
x = int(x)
except:
return render_template('index.html', results="Non string value passed to x\n Please Provide an integer value")
expression = request.form['expression']
try:
results = eval(expression)
print(results)
except Exception as e:
message = """Oops!
Your expression syntax is incorrect!
The full returned Traceback:
"""+str(e)
return render_template('index.html', results=message)
return render_template('index.html', results=results)
if __name__ == "__main__":
#import sys
# print(sys.version)
# 3.7.6 (default, Jan 8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)]
app.run(debug=True)
# maybe it runs now!