forked from stelligent/ghost-in-shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
29 lines (20 loc) · 601 Bytes
/
Copy pathapp.py
File metadata and controls
29 lines (20 loc) · 601 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
from flask import render_template, url_for, Flask, request, jsonify
app = Flask(__name__)
# Recursive factorial function
def fact(n):
return 1 if (n < 1) else n * fact(n - 1)
# Default route
@app.route('/', methods=['GET'])
def index():
return render_template('index.html')
# Factorial route for form post
@app.route('/factorial/', methods=['GET', 'POST'])
def factorial():
n = int(request.json['number'])
result = fact(n)
data = {'factorial': result}
data = jsonify(data)
return data
# Main func
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)