Advertisement
Guest User

asf

a guest
Jan 30th, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. from flask import render_template, flash, redirect
  2. from app import app
  3. from forms import LoginForm
  4. import random
  5. import time
  6.  
  7. counter = 0
  8.  
  9. @app.route('/index', methods = ['GET'])
  10. def index():
  11.     answer = 0
  12.     first = 0
  13.     second = 0
  14.     form = LoginForm()
  15.     first = random.randint(1, 10)
  16.     second = random.randint(1, 10)
  17.     answer = first*second
  18.     return render_template("index.html",
  19.         first = first,
  20.         second = second,
  21.         form = form,
  22.         answer = answer)
  23.  
  24. @app.route('/index', methods = ['POST'])
  25. def check():
  26.     numb = 0
  27.     global counter
  28.     if form.validate_on_submit():
  29.         numb = int(form.answer.data)
  30.         if numb == answer:
  31.             counter += 1
  32.             return redirect('/index')
  33.         else:
  34.             counter = 0
  35.             return redirect('/index')
  36.     return render_template("index.html",
  37.         numb = numb,
  38.         counter = counter)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement