-1

I want to make a wabsit wherethe app picks a random number between 0-100 and the user has to guess the number. However every time the user gives an answer the random number changes. What can i do to always have the same number?? I am using python-flask for the website. Here are my two python functions:

@app.route('/')
def home():
    global number
    number = random.randint(0,100)
    return render_template("question.html",number =number)


@app.route('/',methods=['POST', 'GET'])
def result():
    file = open("answers.txt","a", encoding="utf-8")
    output = request.form.to_dict()
    answer = output["name"]
    file.write(f"{answer}\n")
    
    try:
        return render_template('question.html', name = int(answer) , number =number)
    except:
        return render_template('question.html', name = 0 , number =number)

Everytime I refresh the page it changes between two numbers all the time, like I've generated two random numbers, but before I uploaded it with heroku it was working fine.

GeorgeP
  • 9
  • 1
  • 5

0 Answers0