0
Next, I am creating a game in order to learn, however, I need this game to "reset" when the amount of attempts is reached. At the beginning of the code I have the following:
from random import randint
number = (randint(1, 100))
It generates the random value so that the user tries to hit it. The user has 10 chances to hit, however, at the moment, after the 10 attempts the game continues to have as reference the same value "number"
This "game" runs on the flask server with a front in HTML, I would like to know how I do so that arriving in 10 attempts it gives a "reset" on the server, thus generating a new number for a new game.
Follow the server code:
# // Function import for use make_response for cookies
from flask import Flask, make_response
# //Function import request in directory static local server
from flask import Flask, request, send_from_directory
# //Function that uploads files to the local server at http://localhost:5000/index.html
from flask import Flask, request
app = Flask(__name__, static_url_path="", static_folder="static")
# //Function to generate a random integer value in the variable number
from random import randint
number = (randint(1, 100))
print(number)
# //Route function to receive the POST of the guess form
@app.route('/adivinhar', methods=['POST'])
def adivinhar():
# //Reference number of html for variable N for comparison purposes
n = int(request.form.get('number'))
# //Guard clause for cookie not defined
if request.cookies.get('attemp'):
# //Transform cookie string in interger for var a
a = request.cookies.get('attemp')
a = int(a)
else:
a = 0
# //the print(a) will shit if there is no cookie
# //RETURN FOR LOSE
The idea is not to use any application and not to use JS, thanks for the tip.
– Phelipe Gomes