Skip to content

Instantly share code, notes, and snippets.

@rogeriochaves
Last active January 5, 2020 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rogeriochaves/cd1c82efaf9081d4817ce24c05e45d7f to your computer and use it in GitHub Desktop.
Save rogeriochaves/cd1c82efaf9081d4817ce24c05e45d7f to your computer and use it in GitHub Desktop.
questions_so_far = []
answers_so_far = []
@app.route('/')
def index():
global questions_so_far, answers_so_far
question = request.args.get('question')
answer = request.args.get('answer')
if question and answer:
questions_so_far.append(int(question))
answers_so_far.append(float(answer))
probabilities = calculate_probabilites(questions_so_far, answers_so_far)
print("probabilities", probabilities)
questions_left = list(set(questions.keys()) - set(questions_so_far))
if len(questions_left) == 0:
result = sorted(
probabilities, key=lambda p: p['probability'], reverse=True)[0]
return render_template('index.html', result=result['name'])
else:
next_question = random.choice(questions_left)
return render_template('index.html', question=next_question, question_text=questions[next_question])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment