-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.py
47 lines (43 loc) · 1.41 KB
/
server.py
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
from flask import Flask, render_template, request, redirect, session
app = Flask(__name__)
app.secret_key = 'numbers are great'
# root route
@app.route('/')
def index():
print session
if "response" in session:
if session["response"] == "correct":
show = "correct"
elif session["response"] == "high":
show = "high"
elif session["response"] == "low":
show = "low"
elif session["response"] == "start":
show = "start"
else:
show = "start"
return render_template('index.html', response = show)
# guess route
@app.route('/guess', methods = ['POST'])
def user_guess():
session["guess"] = int(request.form['guess'])
import random
if "randomNum" in session:
if session["randomNum"] == None:
session["randomNum"] = random.randrange(0, 101)
else:
session["randomNum"] = random.randrange(0, 101)
if session["randomNum"] == session.get("guess"):
session["response"] = "correct"
elif session.get("guess") > session['randomNum']:
session["response"] = "high"
elif session.get("guess") < session['randomNum']:
session["response"] = "low"
print str(session['randomNum']) + " was the number!"
return redirect('/')
@app.route('/reset')
def reset():
session["response"] = "start"
session["randomNum"] = None
return redirect('/')
app.run(debug = True)