-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
29 lines (26 loc) · 826 Bytes
/
Copy pathapp.py
File metadata and controls
29 lines (26 loc) · 826 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 Flask, request, render_template_string
import random
app = Flask(__name__)
@app.route('/app', methods=['GET', 'POST'])
def game():
number = random.randint(1, 50)
message = ""
if request.method == "POST":
try:
guess = int(request.form['guess'])
if guess < number:
message = "Too low!"
elif guess > number:
message = "Too high!"
else:
message = "Correct!"
except:
message = "Invalid input"
return render_template_string("""
<h1>Guess the Number (1-50)</h1>
<form method="post">
<input name="guess" type="number" required>
<input type="submit" value="Guess">
</form>
<p>{{message}}</p>
""", message=message)