-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestion_5.py
More file actions
30 lines (24 loc) · 742 Bytes
/
question_5.py
File metadata and controls
30 lines (24 loc) · 742 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
# Here is some starter code for a Flask Web Application. Expand on that and include
# a route that simulates rolling two dice and returns the result in JSON.
# You should include a brief explanation of your code.
from flask import Flask
app = Flask(__name__)
import json
import random
@app.route('/')
def hello_world():
return 'Hello World!'
@app.route('/roll_dice')
def roll_dice():
if request.method == "GET":
dice_1 = random.int(1, 6)
dice_2 = random.int(1, 6)
result = {
'dice_1': dice_1,
'dice_2': dice_2
}
return jsonify(result)
# Create an api that take a GET request and return a json file.
if __name__ == '__main__':
app.debug = True
app.run()