Skip to content

Instantly share code, notes, and snippets.

@rogeriochaves

rogeriochaves/server.py

Last active Jan 5, 2020
Embed
What would you like to do?
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