Answer the question
In order to leave comments, you need to log in
Why doesn't counter work in Python/Flask?
There is a page on Python/Flask. The user must enter the correct answer to multiply the two numbers and the score counter must increase by 1. But unfortunately it doesn't work. Tell me please. There is a screen.
from flask import render_template, flash, redirect
from app import app
from forms import LoginForm
import random
import time
counter = 0
@app.route('/', methods = ['GET', 'POST'])
@app.route('/index', methods = ['GET', 'POST'])
def index():
numb = 0
answer = 0
first = 0
second = 0
global counter
form = LoginForm()
first = random.randint(1, 10)
second = random.randint(1, 10)
answer = first*second
if form.validate_on_submit():
numb = int(form.answer.data)
if numb == answer:
counter += 1
return redirect('/index')
else:
counter = 0
return redirect('/index')
return render_template("index.html",
first = first,
second = second,
form = form,
numb = numb,
answer = answer,
counter = counter)
<h2><p align="center">{{first}}*{{second}}=</p></h2>
<form action="" method="post" name="answer">
{{form.hidden_tag()}}
<p align="center">{{form.answer(size=40)}} <input type="submit" value="Ответить"></p>
<p align="center">Счет: {{counter}}</p><br>
Answer the question
In order to leave comments, you need to log in
Your program logic is not working. :) You think the answer is wrong. What is this?
first = random.randint(1, 10)
second = random.randint(1, 10)
answer = first*second
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question